Arithmetic operations on dates ?

jbv jbv.silences at Club-Internet.fr
Sat Feb 26 07:29:14 EST 2005



Michael,

Thank you so much !
JB

> Use the dateItem format of the date:
>
> Convert your date to date items.
>    convert myDate to dateItems
> Now add your time increments to the appropriate item
>    add 17 to item 5 of myDate -- hours
>    add 3 to item 4 of myDate -- days
> Then convert to dateItems again
>    convert myDate to dateItems
> Convert back to the date format you were using
>
> To increment by weeks just add or subtract 7 days, item 3 of the
> dateItems.
>
> To increment by months just add the number of months to item 2 of the
> dateItems.
>
> Your February problem will be taken care of automatically if you are
> incrementing by the number of months.
>
> Use seconds only when you want to know how many days are between two
> dates.
>   put (dateInSeconds1-dateInSeconds2)/(86400) into theDaysInBetween
>
> Using item 7 of the dateItems allows you to calculate dates such as
> 'the second Monday of March.'
>
> And so on.
>
> Michael
>
> On Feb 26, 2005, at 4:55 AM, jbv wrote:
>
> > Hi revolutionaries,
> >
> > What is the best way to make artithmetic
> > operations on dates ? For instance I have
> > a list of events stored with the date & time
> > of occurence, and I'd like to quickly pick
> > up those that took place during the last 17
> > hours, or the last 3 days, or the last 7 weeks
> > or the last 19 months...
> >
> > I know this can be done with SQL but I don't
> > want to set up a database just for that...
> > The best thing I came up with is to convert each
> > event date into seconds, subtract the amount of
> > seconds of the interval of time, and then pick up
> > all items greater than that...
> > But I have the feeling that computing the interval
> > in seconds might get tricky when there's a february
> > 29 in it (for instance)...
> >
> > Any better idea ?
> > Thanks,
> > JB
> >
> > _______________________________________________
> > use-revolution mailing list
> > use-revolution at lists.runrev.com
> > http://lists.runrev.com/mailman/listinfo/use-revolution
> >
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution



More information about the use-livecode mailing list