Calculating and converting 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
joran
Posts: 20
Joined: Fri May 13, 2016 1:00 pm

Calculating and converting date

Post by joran » Sun May 15, 2016 5:05 pm

Hi there, I'm new to this forum and my name is Joran (from Gothenburg, Sweden)

Slowly but steady, learning more and more about LC, a great coding language. To name it "Live Code" seems symbolically totally wright.
Well, I have a question in my pursuit to build a small app that calculates dates, its a kind of simple Time travel gadget maybe . . .

If I think like this:
Input a "year" into a field //ex. 1956 // and into another field a "month" // ex. 4 //and the last field a "day" // ex. 17 //

How do I convert these fields above // year, month, day // into seconds

The Idea for this little app is to do "Time jumps" forward and backward in time, based on user input.
from my understanding, which is quit limited so far, I would be best of to convert a users input to seconds
and base calculations on that info. And after that convert the calculations into "dateitems" for later graphic presentation
of the results.

I'd would be very pleased to receive some guiding help . . .

// Joran

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Calculating and converting date

Post by Klaus » Sun May 15, 2016 5:22 pm

Hi Joran,

1. welcome to the forum! :D

2. Here some great learning resources:
http://www.hyperactivesw.com/revscriptc ... ences.html

3. To your problem:
You need to create a valid date from the three fields like this:
...
put fld "month" & "/" & fld "day" & "/" & fld "year" into tDate
...
## Now tData contains a valid data, if the entries in the fields are correct and only numbers!
## You will need to do some errorchecking still!

## Now you can convert that date to seconds and do your computations:
convert tData from date to seconds
...
Hope that helps!


Best

Klaus

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

Re: Calculating and converting date

Post by dunbarx » Sun May 15, 2016 5:30 pm

Hi.

What Klaus said.

Know that the "seconds" is a continuously running timer that started on the stroke of midnight, Jan 1, 1970. You can use negative seconds to go back in time. This only works about 1000 years, though. There is a thread on the forum that dealt with this, somewhere.

Craig Newman

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

Re: Calculating and converting date

Post by dunbarx » Sun May 15, 2016 5:33 pm


joran
Posts: 20
Joined: Fri May 13, 2016 1:00 pm

Re: Calculating and converting date

Post by joran » Sun May 15, 2016 6:11 pm

Hi again // Thank you very much for your quick reply.

I'll tested it and it works,also dowloaded your tip for more learning

// Joran

joran
Posts: 20
Joined: Fri May 13, 2016 1:00 pm

Re: Calculating and converting date

Post by joran » Sun May 15, 2016 6:15 pm

Thanks to you too Craig.

I'll will check it out.

// Joran

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Calculating and converting date

Post by MaxV » Mon May 16, 2016 5:13 pm

Hi all,
I remember everybody that there is the time and date library for livecode available here: https://github.com/derbrill/libdate
You may contribute to it :D
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply