Compare dates question

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Compare dates question

Post by Pistris » Thu Nov 07, 2019 2:53 am

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

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Compare dates question

Post by bangkok » Thu Nov 07, 2019 4:37 am

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

Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Re: Compare dates question

Post by Pistris » Thu Nov 07, 2019 4:47 am

Worked like a charm

Thanks Bangkok

Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Re: Compare dates question

Post by Pistris » 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?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Compare dates question

Post by FourthWorld » Thu Nov 07, 2019 4:59 am

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Compare dates question

Post by FourthWorld » Thu Nov 07, 2019 5:00 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Compare dates question

Post by [-hh] » Thu Nov 07, 2019 5:01 am

There is a very good LiveCode date library
https://github.com/derbrill/libdate
shiftLock happens

Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Re: Compare dates question

Post by Pistris » Thu Nov 07, 2019 5:52 am

very useful tips indeed
thanks you very much guys

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Compare dates question

Post by dunbarx » Thu Nov 07, 2019 2:45 pm

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”