kedar
January 3, 2022, 12:25pm
1
Hi,
#: 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.
Kedar
kedar:
However, I am not clear format of string accepted in StrToDateTime() especially inclusive of hh, mm, ss.
dt_str1 = "2022-01-03 09:00:00";
dt1 = _DT(dt_str1); // _DT function is equivalent to StrToDateTime() function
printf("DT1: %s", DateTimeToStr(dt1));
https://www.amibroker.com/guide/afl/strtodatetime.html
https://www.amibroker.com/guide/afl/_dt.html
2 Likes
Tomasz
January 3, 2022, 3:28pm
3
kedar:
However, I am not clear format of string accepted in StrToDateTime() especially inclusive of hh, mm, ss.
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
kedar
January 3, 2022, 5:56pm
4
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.
Kedar
kedar
January 4, 2022, 2:28am
5
Oh, that easy. Thanks a lot 'fxshrat'. That helps fast.
Many thanks.
Kedar
system
Closed
April 14, 2022, 2:29am
6
This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.