Page 1 of 1

Calculating and converting date

Posted: Sun May 15, 2016 5:05 pm
by joran
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

Re: Calculating and converting date

Posted: Sun May 15, 2016 5:22 pm
by Klaus
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

Re: Calculating and converting date

Posted: Sun May 15, 2016 5:30 pm
by dunbarx
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

Re: Calculating and converting date

Posted: Sun May 15, 2016 5:33 pm
by dunbarx

Re: Calculating and converting date

Posted: Sun May 15, 2016 6:11 pm
by joran
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

Re: Calculating and converting date

Posted: Sun May 15, 2016 6:15 pm
by joran
Thanks to you too Craig.

I'll will check it out.

// Joran

Re: Calculating and converting date

Posted: Mon May 16, 2016 5:13 pm
by MaxV
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