I am trying to parse the date using ParseDateTime
method provided by COleDateTime
class. But parsing of two different dates in the same program is returning inconsisent values for the month.
Code Snippet:
COleDateTime dtCreated;
dtCreated.ParseDateTime(safe_cast<CString>(strCreatedDate));
Inconsistent RESULTS:
if strCreatedDate
= "10/7/2020" (in mm.dd.yyyy format)
then dtCreated.GetMonth()
= 7 (but it should be 10)
if strCreatedDate
= "7/29/2020" (in mm.dd.yyyy format)
then dtCreated.GetMonth()
= 7 (in this case, it is correct)
UPDATE:
The value of date present in the strCreatedDate
vairable could be "dd.mm.yyyy" OR "mm.dd.yyyy" format. But I do have the information about the data format available in a separate variable. Based on the format, I want COleDateTime
to correctly parse the DateTime string. How can I do that?
Since
String^
is your input you could useDateTime::ParseExact
, and then convertDateTime
toCOleDateTime
usingDateTime.ToOADate
: