Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Applescript: date formatting

7 views
Skip to first unread message

Jolly Roger

unread,
Mar 27, 2016, 12:34:51 PM3/27/16
to
On 2016-03-27, JF Mezei <jfmezei...@vaxination.ca> wrote:
>
> the following applescript:
> write "date: " & aPhoto's date & return to outfile
>
> produces:
> date: Tuesday, 10July, 2012 at 13:22:10
>
> Which is a useless date for more processing.
>
> So, is it a case of having to write some complex subroutine to generate
> a proper ISO date format with lots of string concatenation and
> truncation (I suspect I would have to add 100 to all values and then
> take the last 2 digits to get a leading 0 for values less than 10).
>
> Or is there something really simple which I have not found ?

[cross posted to alt.comp.lang.applescript]

-- begin script
return FormatDateTime(current date)

--------------------------------------------------------------------------------------------

on FormatDateTime(theDate)
set theDate to theDate as date
set D to characters -2 through -1 of ("0" & theDate's day) as
text
copy theDate to tempDate
set the month of tempDate to January
set M to characters -2 thru -1 of ("0" & 1 + (theDate - tempDate
+ 1314864) div 2629728) as text
set Y to characters -1 thru -4 of ((year of theDate) as text) as
text
set hh to "0" & theDate's hours as text
set hh to characters ((count of hh) - 1) through (count of hh)
of hh
set mm to "0" & theDate's minutes as text
set mm to characters ((count of mm) - 1) through (count of mm)
of mm
set ss to "0" & theDate's seconds as text
set ss to characters ((count of ss) - 1) through (count of ss)
of ss
return (Y & "-" & M & "-" & D & " @ " & hh & ":" & mm & ":" & ss
as text)
end FormatDateTime
-- end script

--
E-mail sent to this address may be devoured by my ravenous SPAM filter.
I often ignore posts from Google. Use a real news client instead.

JR
0 new messages