Calculating the time in seconds for a future date

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
matgarage
Posts: 73
Joined: Sat Apr 20, 2013 11:39 am

Calculating the time in seconds for a future date

Post by matgarage » Tue Mar 31, 2015 5:42 pm

Hi

Is it a way with Livecode to calculate the seconds (the Livecode function) but for a date in the future ?

ex : 29 february 2016, 00:00 h = in seconds from 1/1/1970

Any idea ? :?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Calculating the time in seconds for a future date

Post by FourthWorld » Tue Mar 31, 2015 5:46 pm

put "3/31/15" into tDate
convert tDate to seconds
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

matgarage
Posts: 73
Joined: Sat Apr 20, 2013 11:39 am

Re: Calculating the time in seconds for a future date

Post by matgarage » Tue Mar 31, 2015 6:47 pm

So simple, so quick, thank you.

I'm going to play :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Calculating the time in seconds for a future date

Post by dunbarx » Tue Mar 31, 2015 7:21 pm

Midnight on Jan 1, 1970 is the baseLine. But watch out for your timeZone:

Code: Select all

on mouseUp
   put 0 into ff
   convert ff to dateItems
   answer ff
end mouseUp
Unless you are near the Greenwich Observatory, you will get what might seem to be odd information.

Craig Newman

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Calculating the time in seconds for a future date

Post by FourthWorld » Tue Mar 31, 2015 8:18 pm

The seconds accounts for time zone based on local machine settings. So 0 in GMT is 8 hours earlier than PDT, where I am, and I get "1969,12,31,16,0,0,4", which seems about right.

This makes seconds and internet date two of the most useful formats we have for storing time values, as they both keep track of time all the way down to the second and they both account for time zones. The seconds is more compact, a good choice when storage space is a consideration, and internet date is more human-readable, great for display.

There's also milliseconds for when finer accounting of time is needed, and if you need to account for time even finer there's "the long seconds", which goes down to microseconds.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

matgarage
Posts: 73
Joined: Sat Apr 20, 2013 11:39 am

Re: Calculating the time in seconds for a future date

Post by matgarage » Fri Apr 03, 2015 4:31 pm

No problem for me with the time zone, i'm in France.

I suppose that adding or substracting (3600 * x) to the seconds (where x = the GMT+x value) will correct the gap.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Calculating the time in seconds for a future date

Post by Thierry » Fri Apr 03, 2015 4:48 pm

matgarage wrote:No problem for me with the time zone, i'm in France.

I suppose that adding or substracting (3600 * x) to the seconds (where x = the GMT+x value) will correct the gap.
As the week-end is coming, you might have 10 mn free for this:

https://www.youtube.com/watch?v=-5wpm-g ... e=youtu.be

Was posted on the user's list by Peter.

Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Post Reply