Calculating and converting date
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Calculating and converting date
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
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
Hi Joran,
1. welcome to the forum!
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
1. welcome to the forum!

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
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
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
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
I'll tested it and it works,also dowloaded your tip for more learning
// Joran
Re: Calculating and converting date
Thanks to you too Craig.
I'll will check it out.
// Joran
I'll will check it out.
// Joran
Re: Calculating and converting date
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
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

Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w