c++parsingvisual-c++mfccoledatetime

How can I parse a std::string (YYYY-MM-DD) into a COleDateTime object?


I have a COleDateTime object and I want to parse a date string in the format YYYY-MM-DD.

The string variable, for example, is:

std::string strDate = "2022-07-04";

COleDateTime allows me to use ParseDateTime to parse a string, but I see no way to tell it what format the components of the date string are. In C# I can do such with DateTime.Parse....


Solution

  • Based on the suggestion by @xMRi in the comments I have decided to use:

    CString strDutyMeetingDate = CString(tinyxml2::attribute_value(pDutyWeek, "Date").c_str());
    int iDay{}, iMonth{}, iYear{};
    if(_stscanf_s(strDutyMeetingDate, L"%d-%d-%d", &iYear, &iMonth, &iDay) == 3)
    {
        const auto datDutyMeetingDate = COleDateTime(iYear, iMonth, iDay, 0, 0, 0);
    }