Add 1 hour to time

Sarah Reichelt sarah.reichelt at gmail.com
Mon Apr 17 17:06:28 EDT 2006


> I know there must be a simple way to do this but it's excaping me.  I
> just need to add one hour to a time that I've set.  Here's the code that
> doesn't work but it's the general idea:
>
> on mouseUp
>   put "10:00 AM" into currentTime
>   put "currentTime + 1:00" into FutureTime
>   answer FutureTime
> end mouseUp
>
> Can someone show me how to set a time into a variable and add an hour to
> it.  Thanks,  Jeff

I always use dateItems for any time or date additions, because it
handles the wrap-arounds so well. With adding 1 hour to a time, it
isn't so important, but what if you wanted to add some days to a date.
You wouldn't know without a lot of checking if the date was now
invalid e.g. 32nd March. If you convert your time/date to date items,
add to the relevant item in the dateItems string, then convert back
again, all this is taken care of.

For more info, you might like to check out the scripting conference
stack on Dates & Times that I wrote. It's #12 in the list at
<http://support.runrev.com/scriptingconferences/>

Cheers,
Sarah



More information about the use-livecode mailing list