• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting time Stamp from Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Getting time Stamp from Applescript
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Getting time Stamp from Applescript (From: "Troy, Drew" <email@hidden>)

  • Prev by Date: Re: Sequential renumbering in InDesign CS3
  • Next by Date: Re: Getting time Stamp from Applescript
  • Previous by thread: Re: Getting time Stamp from Applescript
  • Next by thread: Re: Getting time Stamp from Applescript
  • Index(es):
    • Date
    • Thread