Need "Current Date" in Numeric Form

I am creating a script that will be called upon at differnt times to create a file. I will need a unique file name to be created and since the apple script will be called upon at different intervals, I would like to utizlie the current date & time in the file name.

For example, I would like my file name to be “somePrefix_0903041435.pdf” where 090304 = September 03, 2004 & the 1435= 2:35p.

However:

set t to (current date)

displays: date "Friday, September 3, 2004 2:35:11 PM

Anyone knw how I could convert it to the format I am looking for?

Scott,

It’s not very elegant, but it gets the job done:

set cDate to current date
set shortDate to short date string of cDate
set theMonth to word 1 of shortDate
if length of theMonth is 1 then set theMonth to "0" & theMonth
set theDay to word 2 of shortDate
if length of theDay is 1 then set theDay to "0" & theDay
set theYear to year of cDate
set DateString to theMonth & theDay & theYear

set theTime to time string of cDate
set theHour to word 1 of theTime as number
set DayNight to last word of theTime
if DayNight is "PM" then set theHour to theHour + 12
set theHour to theHour as text
if the length of theHour is 1 then set theHour to "0" & theHour
set theMinutes to word 2 of theTime
if the length of theMinutes is 1 then set theMinutes to "0" & theMinutes
set TimeString to theHour & theMinutes
set FinalString to DateString & TimeString

Hope this helps. I KNOW this can be simplified, however, it’s not bad for being done “on the fly.”

Brad Bumgarner, CTA

Brad,

Thank you for your input.

That works like a charm… If anyone knows a shorter way to achieve this, please let me know, but for now this will get the job done.

Thanks, again!

set theDate to (do shell script “date “+%m%d%y%H%M””)

That is just pretty.

Thank you.

D’oh!! I SHOULD have thought of that. I’ve played around with it enough!!

Very nice Donkley Hoatie.

Brad Bumgarner, CTA

Thank you all for your comments.

You can format the date almost any way you like via the command line. For more info see

man strftime

Examples…

set theDate to (do shell script "date +%v")
-->4-Sep-2004
set theDate to (do shell script "date +%F\ @\ %T")
-->2004-09-04 @ 02:09:20