Manipulation of time and date

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Hapache
Posts: 4
Joined: Thu Feb 24, 2011 12:42 pm

Manipulation of time and date

Post by Hapache » Thu Feb 24, 2011 12:50 pm

Hello,
I'm new in Livecode use.
I done tutorials and some search on the lessons part of the site.
I would like to manipulate date and time.. just add some days, some hours or minutes.
I found the wait to get the time & date, to convert it into item.... so I can manipulate Items but therefore I don't have any automatic controls on format (35 minutes + 30 = 65 minutes !!) and even I cannot convert back into a "normal" time variable.
Can somebody help me ?

Thanks

Hapache

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

Re: Manipulation of time and date

Post by Klaus » Thu Feb 24, 2011 1:08 pm

Hi Hapache,

please check "convert" and "dateitems" in the docs (LiveCode ditionary), which lets you do what you want.
You only need to "convert" the modified "dateitems" back to "date" or whatever, LiveCode will manage the correct "new" date"!

Example:
...
## We want to know the date in 27 days from today
put the date into tDate
convert tDate to dateitems
add 27 to item 3 of tDate
convert tDate to date
answer "In 27 days we will have:" && tDate
...
You get the picture :D

Best

Klaus

P.S.
Welcome to the forum!

Hapache
Posts: 4
Joined: Thu Feb 24, 2011 12:42 pm

Re: Manipulation of time and date

Post by Hapache » Thu Feb 24, 2011 4:17 pm

Thanks,
I needed the "convert XX to date or to time" function.... it's what I called convert back.
It works.

Thanks for this quick answer

Hapache

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

Re: Manipulation of time and date

Post by dunbarx » Thu Feb 24, 2011 8:56 pm

Also note that the convert command does all the math for you. It is very nice that way. So you can add or subtract anything to any of those dateItems, and the result will still be valid. In other words, if you add 1000 days to item 3, when you convert back, the year, month and day will be correct.

Craig Newman

Post Reply