Re: Subtract 1 month from date
Re: Subtract 1 month from date
- Subject: Re: Subtract 1 month from date
- From: Nigel Garvey <email@hidden>
- Date: Thu, 9 Dec 2004 10:11:52 +0000
In my message of Thursday, 9 December 2004 02-ish GMT I wrote:
> on addCalendarMonths(theDate, m) -- m negative for subtractions
> copy theDate to newDate
> set {y, m} to {m div 12, m mod 12}
> if m < 0 then set {y, m} to {y - 1, m + 12}
> set newDate's year to (newDate's year) + y
> if m is not 0 then tell newDate to set {day, day} to {32 * m, day}
> if newDate's day is not theDate's day then set newDate to newDate -
>(newDate's day) * days
>
> return newDate
> end addCalendarMonths
I'm afraid this was just showing off my calendar month arithmetic
handler, which seemed relevant to the discussion. But if Eric
specifically wants just the first of the current month and the first of
the previous month, this can be done in two lines:
tell (current date) to set {day, endDate} to {1, it}
tell (endDate - days) to set {day, startDate} to {1, it}
-- Then get the short date strings.
(Obviously, any date can be used in place of the current date.)
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden