Format of String in StrToDateTime() when using hh, mm, ss inclusive Date


#: I wish to compare two dates for which I have DD, MM, YYYY, hh, mm, ss are available in numeric form.

#: I see DateTimeDiff() can do the job.

#: For that, I see StrToDateTime() useful.

#: However, I am not clear format of string accepted in StrToDateTime() especially inclusive of hh, mm, ss.

Can somebody guide, if this is right way to compare and how do I make string formatting to use in StrToDateTime()?

Thanks a lot.


dt_str1 = "2022-01-03 09:00:00";
dt1 = _DT(dt_str1); // _DT function is equivalent to StrToDateTime() function

printf("DT1: %s", DateTimeToStr(dt1));


Under the hood, sting to date time conversion is done by Windows VarDateFromStr function (oleauto.h) - Win32 apps | Microsoft Docs

It handles whatever date format you have set in your Control Panel / Regional Settings.
In addition to that it always handles ISO format (YYYY-MM-DD hh:mm:ss). It also tries to "figure it out" in case of format that is neither set in control panel and it is not ISO. If it sees 1970/01/13 it is likely to figure it out that it is January 13, 1970. But in case of 1970/01/02 it is not clear if it is January 2nd or Feburary 1st.
So if you have a choice, use ISO format.

1 Like

OK, great inputs, quick one Tomasz. I shall be trying this tomorrow morning, itself. Many thanks. I think I should be good at the end tomorrow.

Thanks again.


Oh, that easy. Thanks a lot 'fxshrat'. That helps fast.

Many thanks.


This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.