Date function

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
Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Date function

Post by Mariasole » Tue May 07, 2013 9:53 pm

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
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

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

Re: Date function

Post by Klaus » Tue May 07, 2013 10:04 pm

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Date function

Post by jmburnod » Tue May 07, 2013 10:07 pm

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
https://alternatic.ch

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: Date function

Post by Mariasole » Tue May 07, 2013 11:45 pm

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
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

Post Reply