Re: numeric date
Re: numeric date
- Subject: Re: numeric date
- From: Nigel Garvey <email@hidden>
- Date: Sat, 19 Jul 2003 18:09:09 +0100
email@hidden wrote on Sat, 19 Jul 2003 11:08:09 +0200:
>
I need to convert the month from the current date to a 2-digit number. My
>
purpose is to make a folder name, like 2003.07.19: that's why I aggregate
>
the year, the month and the day on the last line.
>
>
In the pre-OS X years, I could do this with one line, like
>
>
set d to format_date_using((current date), ".", true, false, {"YY", "MM",
>
"DD"})
>
>
The script below does the job, but does anybody have a better solution?
>
>
set d to (current date) as text
>
set m to word 2 of d
>
set y to "January February March April May June July August September
>
October November December"
>
repeat with x from 1 to 12
>
if word x of y is equal to m then exit repeat
>
end repeat
>
set m to x as text
>
if length of m < 2 then set m to "0" & m
>
set d to word 4 of d & "." & m & "." & word 3 of d
The main problem with '(current date) as text' is that the layout of the
text depends on the user settings on the host computer. On my machine,
your script's final output is "2003.12.July", because my machine's set up
to format date strings as: "Saturday, 19 July 2003 17:48:42". Yours
presumably has the month and the day the other way round. If the script's
just for your own use, that's fine - and it's more satisfying running
your own scripts than other peoples. :-)
To get the same result on anyone's machine, you could do something like
the following. It's based on my development of Emmanuel's "French
Vanilla" method for month numbers:
set d to current date
copy d to b
set b's month to January
tell ((d's year) * 10000 + (b - 2500000 - d) div -2500000 * 100 + (d's
day)) as string
set dStr to text 1 thru 4 & "." & text 5 thru 6 & "." & text 7 thru 8
end tell
NG
_______________________________________________
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.