Mission accomplished!
My original problem was comparing a date as it appears in an HTTP response, like
which follows the standards
https://tools.ietf.org/html/rfc2616#page-20 ,
https://tools.ietf.org/html/rfc1123#page-55 and
https://tools.ietf.org/html/rfc822#section-5 ,
with a date provided by the OS, specifically with this command
whose format can vary.
Now, with what I learned here today, I just need to convert both dates to ISO and then run the comparison.
Code: Select all
$first_date = "Mon, 05 Nov 2012 11:25:28 GMT";
$second_date = property("Write", "<xy>");
//CONVERTING THE FIRST DATE TO ISO 8601
//strip the name of the day and the GMT
$first_date = substr("$first_date", "5", "-4");
//reorder the date in the yyyy-mm-dd format
$first_date = regexreplace("$first_date", "(\d{2}) ([a-z]{3}) (\d{4})", "$3-$2-$1");
//replace the literal month with its numerical value
$first_date = replacelist("$first_date", "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", "01,02,03,04,05,06,07,08,09,10,11,12", ",");
//CONVERTING THE SECOND DATE TO ISO 8601
$second_date = formatdate ("$second_date", "yyyy-mm-dd hh:nn:ss");
//COMPARISON (IN SECONDS)
$delay = datediff("$first_date", "$second_date", "s");
With XY 11.70.0106 always returns 86176 seconds.
Thank you Channing for the suggestion! Looks like I already had whatever I needed.
0.02 € time...
@Don
Thank you, knowing that ISO works in all those functions is a great starting point. As PeterH says, saying it so in the Help will save a lot of headaches.
I would write that format() , formatdate () and datediff() work correctly when input is in local format and ISO format.
Also, would be great if you can shed light on the accepted separators. For local Windows offers ".", "/" and "-", while ISO 8601 (
https://en.wikipedia.org/wiki/ISO_8601 ) is more complex.
I also support PeterH's suggestion: you could add "local" and "ISO" as format shorthands to quickly convert between them.
However, I still believe there's a missing part, i.e. converting from an user defined format to either local or ISO quickly. An inverse formatdate(), so to speak, where you specify the input and it's structure.