Re: numeric date
Re: numeric date
- Subject: Re: numeric date
- From: Rob Jorgensen <email@hidden>
- Date: Sat, 19 Jul 2003 10:53:38 -0400
At 11:08 AM +0200 7/19/03, email@hidden wrote:
Hello, list,
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
I'm not saying this is better but if you ever need to work with
several dates in the same script, here's another way using a handler
found on this page.
<
http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.08.htm>
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 add_leading_zeros(x, 1)
set d to word 4 of d & "." & m & "." & word 3 of d
on add_leading_zeros(this_number, max_leading_zeros)
set the threshold_number to (10 ^ max_leading_zeros) as integer
if this_number is less than the threshold_number then
set the leading_zeros to ""
set the digit_count to the length of ((this_number
div 1) as string)
set the character_count to (max_leading_zeros + 1) -
digit_count
repeat character_count times
set the leading_zeros to (the leading_zeros &
"0") as string
end repeat
return (leading_zeros & (this_number as text)) as string
else
return this_number as text
end if
end add_leading_zeros
--
Rob Jorgensen
Ohio, USA
_______________________________________________
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.