Re: Simple date question
Re: Simple date question
- Subject: Re: Simple date question
- From: Nigel Garvey <email@hidden>
- Date: Tue, 15 Mar 2005 21:00:19 +0000
Andrew Oliver wrote on Tue, 15 Mar 2005 11:02:36 -0800:
>On 3/15/05 10:40 AM, "Bernardo Hoehl" <email@hidden> wrote:
>> How do I get the last day of the current month?
>One trick is to add sufficient days to the current date to force you into
>the next month, the subtract back a sufficient number of days, like:
>
>set cd to (get current date)
>--> date "Tuesday, March 15, 2005 11:00:00 AM"
>
>set day of cd to 32
>-- this forces you to some day in the next month
>-- since no month has more than 31 days
>--> date "Friday, April 1, 2005 11:00:00 AM"
>
>set day of cd to 1
>--> reset back to the first of the month
>--> date "Friday, April 1, 2005 11:00:00 AM"
>
>set cd to cd - (1 * days)
>-- subtract one day gets the last day of the preceding month
>--> date "Thursday, March 31, 2005 11:00:00 AM"
This can be slightly optised to:
set day of cd to 32
set cd to cd - ((cd's day) * days)
-- subtract n days from the nth of next month
-- (same as subtracting 1 day from the first)
Paul Berkowitz wrote on Tue, 15 Mar 2005 11:12:45 -0800:
>Andrew's way (which might originally be Nigel's way, in fact)
:-)
There's also Emmanuel's one-line development from that:
tell (current date) to tell it + (32 - (its day)) * days to set
lastDayOfThisMonth to (it - (its day) * days)'s day
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