Page 1 of 1

Compare dates question

Posted: Thu Nov 07, 2019 2:53 am
by Pistris
Hello guys

how do you go about comparing dates?

am trying to compare dates in the following format "10/10/19" but results are erratic

ex.

put the date into vDate
if "10/10/19" => vDate then bla bla bla

what is the correct way of comparing dates

right now am just trying to check if a specific date has passed

thanks

Re: Compare dates question

Posted: Thu Nov 07, 2019 4:37 am
by bangkok
To compare 2 dates : convert them to "seconds".

Code: Select all

   put "12/01/19" into tDate
   
   convert tDate from english date to seconds
   
   put the english date into tDateNow
   
   convert tDateNow from english date to seconds
   
   if tDate>tDateNow then
      answer "After"
   else
      answer "Before"
   end  if

Re: Compare dates question

Posted: Thu Nov 07, 2019 4:47 am
by Pistris
Worked like a charm

Thanks Bangkok

Re: Compare dates question

Posted: Thu Nov 07, 2019 4:50 am
by Pistris
Just out of curiosity , when you convert the date in seconds it starts counting from which year?
I mean second 0 corresponds to what date?

Re: Compare dates question

Posted: Thu Nov 07, 2019 4:59 am
by FourthWorld
Pistris wrote:
Thu Nov 07, 2019 4:50 am
Just out of curiosity , when you convert the date in seconds it starts counting from which year?
I mean second 0 corresponds to what date?
LiveCode uses the "UNIX Epoch": January 1, 1970

Re: Compare dates question

Posted: Thu Nov 07, 2019 5:00 am
by FourthWorld
A useful tip about "seconds": along with "internet date", those are the only two built-in formats that safely convert across time zones. "Seconds" are GMT, and "internet date" contains a time zone signifier.

Re: Compare dates question

Posted: Thu Nov 07, 2019 5:01 am
by [-hh]
There is a very good LiveCode date library
https://github.com/derbrill/libdate

Re: Compare dates question

Posted: Thu Nov 07, 2019 5:52 am
by Pistris
very useful tips indeed
thanks you very much guys

Re: Compare dates question

Posted: Thu Nov 07, 2019 2:45 pm
by dunbarx
Hi.

Check out this thread, which deals with times before the beginning of time.

viewtopic.php?f=9&t=26619&p=138530&hili ... ng#p138530

Craig