Re: How to get Zero (0) before Month ?
Re: How to get Zero (0) before Month ?
- Subject: Re: How to get Zero (0) before Month ?
- From: Kai <email@hidden>
- Date: Tue, 18 Feb 2003 20:37:26 +0000
on Sun, 16 Feb 2003 16:35:40 +0100, Krister Nyman <email@hidden>
wrote:
>
When I use this script :
>
>
set the_months to "January February March April May June July August
>
September October November
>
December"
>
set message_date to current date
>
set mess_year to year of message_date as string
>
set mess_day to day of message_date as string
>
set day_count to count characters in mess_day
>
if day_count = 1 then set mess_day to "0" & mess_day
>
set mess_month to month of message_date as string
>
repeat with x from 1 to count words in the_months
>
if mess_month = word x of the_months then set month_count to x as
>
string
>
end repeat
>
set date_format to mess_year & "/" & month_count & "/" & mess_day
>
>
>
I get result "2003/2/16" thats great, but I wonder how to get this
>
"2003/02/16" ?
>
>
I always want to have month in two numbers, 01,02,03,04,05.....10,11,12
>
like it is with days.
Sorry for coming to this rather late, Krister - but you might also like to
try one of these:
====================================================
set {y, m, d, s} to (current date)'s {year, month, day} & [NO-BREAK]
"JanFebMarAprMayJunJulAugSepOctNovDec"
set {tid, text item delimiters, y, d} to {text item delimiters, [NO-BREAK]
(m as string)'s text 1 thru 3, "" & y, ("0" & d)'s text -2 thru -1}
set {date_format, text item delimiters} to {y & "/" & ("0" & [NO-BREAK]
((s's text item 1's length) + 3) div 3)'s text -2 thru -1 & "/" & d, tid}
-- do something with date_format
====================================================
Besides being a little shorter than the original version, the above is also
significantly faster.
Briefer and faster yet is this variation of what's known around here as the
'French vanilla' method (pioneered by Emmanuel Levy and developed further by
Richard Hartman):
====================================================
set e to current date
copy e to s
set {s's month, {y, d}} to {January, e's {year, day}}
set date_format to "" & y & "/" & ("0" & 1 + (e - s) [NO-BREAK]
div 2500000)'s text -2 thru -1 & "/" & ("0" & d)'s text -2 thru -1
-- do something with date_format
====================================================
--
Kai
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.