Page 1 of 1

Date function

Posted: Tue May 07, 2013 9:53 pm
by Mariasole
Hello!
Excuse my horrible english :( . Thanks to Rev Run that made Live Code open source! :wink: Get to the point.

Is there a function to calculate a date simply... backward or forward in time?

Let me explain:

Today = 7 May 2013.

Tomorrow? (Today + 1) 8 May 2013.

Today - 8? = 30 April 2013.

I hope I explained! I am a beginner!

Sorry if the question will seem stupid. :mrgreen:

Thank you all! Long life to LiveCode!

Mariasole

Re: Date function

Posted: Tue May 07, 2013 10:04 pm
by Klaus
Hi Mariasole,

1. welcome to the forum :D

2. no stupid question at all, you can use "dateitems" for date calculations!
From the dictionary about "dateitems" :
...
The dateItems format is a comma-separated list of numbers:
* the year
* the month number
* the day of the month
* the hour in 24-hour time
* the minute
* the second
* the numeric day of the week where Sunday is day 1, Monday is day 2, and so forth

Here is how to use it:
1. convert your initial date to dateitems
2. add hours, days, week, years to the appropriuate ITEM of dateitems and then
3. convert back to date
4. done :)

Example:
...
## Today:
put the date into tDate
convert tDate to dateitems

## Now we add 7 to ITEM 3, which represent the days, ande Livecode will do all neccessary calculations even if the reach a new month or year etc...!
add 7 to item 3 of tDate

## convert back to date (or long date or whatever DATE offers)
convert tDate to date
answer tDate
## et voily, one week later :)
...
Check "convert", "date" and "dateitems" in the dictionary!


Best

Klaus

Re: Date function

Posted: Tue May 07, 2013 10:07 pm
by jmburnod
Hi Mariasole,
Excuse my horrible english

Yes one more :D

One day have 86400 seconds. You can use it and convert to get what you want

Code: Select all

on mouseUp
   put 1 into tNbDay -- the num of days
   put the seconds into tTodaySec
   put 86400 * tNbDay into tTimePassed
   put  tTodaySec + tTimePassed into tDaysec
   convert tDaysec to short date
   answer "In " && tNbDay && "day we will be the" && tDaysec
end mouseUp
Best regards
Jean-Marc

Re: Date function

Posted: Tue May 07, 2013 11:45 pm
by Mariasole
Thank you! Thank you! Thank you!
Thanks Klaus for your enlightening explanation! :D
Thanks Jean-Marc for your radical solution! 8)
Now I start to work! :mrgreen:
Long Life to Live Code!

Baci!

Mariasole