EASY way to add n days to a date?
zryip theSlug
zryip.theslug at gmail.com
Sun Dec 20 10:04:47 EST 2009
Hi Médard,
You've terribly right. Sorry to have forgot non-english systems.
Thankfully a quick solution exists. By using the useSystemDate
property you'll be able to force RR to use the date settings of your
system. 8) Note that the scope of this property is the current handler
only.
I believe that I was not clear about the calculating itself. To obtain
the last day of a month, you need to pass the first date of the month
as first parameter to the addToDate function.
To make amends here is the function that should be useful regardless
of the language of your system. 8)
Try it and tell us if it works fine for you ;):
on mouseUp
local lMyDate
set useSystemDate to true -- Use the system settings instead of the
RR natural english date
put the date into lMyDate
answer addToDate(firstDateInMonth(lMyDate),0,1,-1)
end mouseUp
function firstDateInMonth pStartDate
-- Return the first day in a month
set useSystemDate to true
convert pStartDate to dateitems
put 1 into item 3 of pStartDate
convert pStartDate to short date
return pStartDate
end firstDateInMonth
function addToDate pStartDate,pAddToYear,pAddToMonth,pAddToDay
-- Allows you to manipulate a date in a single pass
set useSystemDate to true
convert pStartDate to dateitems
add pAddToYear to item 1 of pStartDate
add pAddToMonth to item 2 of pStartDate
add pAddToDay to item 3 of pStartDate
convert pStartDate to short date
return pStartDate
end addToDate
2009/12/20 Medard <liste.revo at medard.on-rev.com>:
> zryip theSlug <zryip.theslug at gmail.com> wrote:
>
>> An easy trick to know the end date of one month without creating
>> complex script to test the number of days in the months, years
>> leap, etc..
>
> clever -- but that doesn't work on "foreign" systems
> i.e. non english languages ;-)
>
> it is still funny to see Revolution to declare some parameter to be "not
> a date" as you prior performed a "put the system" date into fld "xxx"
> ;->
>
> so, the starting date MUST be an "english" one, I mean a "US" date,
> according to the yyyy/dd/mm scheme
>
> my "system date" is yyyy-mm-dd
> (avoiding the slash, used in Unix as file/folder delimitor)
>
> Anyway, after sticking to those caveats, the provided code gives exactly
> what it is intended for, i.e. the date a month minus a day ahead -- not
> the end of the month ;-))
More information about the use-livecode
mailing list