Re: Getting time Stamp from Applescript
Re: Getting time Stamp from Applescript
- Subject: Re: Getting time Stamp from Applescript
- From: Stan Cleveland <email@hidden>
- Date: Thu, 04 Dec 2008 14:09:10 -0800
- Thread-topic: Getting time Stamp from Applescript
On 12/4/08 1:07 PM, "Troy, Drew" wrote:
> I have been trying to get a timestamp from AppleScript but I only seem to be
> able to get it in the form or ³December 4, 2008². I would like to be able to
> get it in the form of ³2008-12-02 16:03:45.180² so that I can perform some
> SQL queries with it.
>
> Does anyone know how to get a date to look like that from AppleScript.
Drew, here¹s some plain-vanilla AppleScript code for the format you want.
Note that AppleScript doesn't natively resolve beyond whole seconds, so I
just tack on the decimal point and three zeros.
Stan C.
set aDate to date "Thursday, December 4, 2008 1:54:45 PM"
set fDate to formatDate(aDate)
--> "2008-12-04 13:54:45.000"
on formatDate(aDate)
set {yr, mo, dy, hr, mn, sc} to ¬
{year, month, day, hours, minutes, seconds} of aDate
return ("" & yr & "-" & addLeadingZero(mo as integer) & "-" & ¬
addLeadingZero(dy) & " " & addLeadingZero(hr) & ":" & ¬
addLeadingZero(mn) & ":" & addLeadingZero(sc) & ".000")
end formatDate
on addLeadingZero(n)
return text -2 thru -1 of ("00" & n)
end addLeadingZero
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden