Re: Epoch Seconds to YYYY-MM-DD
Re: Epoch Seconds to YYYY-MM-DD
- Subject: Re: Epoch Seconds to YYYY-MM-DD
- From: Nigel Garvey <email@hidden>
- Date: Sat, 27 Apr 2013 21:09:23 +0100
Marconi wrote on Sat, 27 Apr 2013 08:25:32 -0700:
>I am trying to pass a number like "1157445071" to a shell script but AS
>keeps converting the passed value, such as "1157445071", to
>"1.157445071E+9" scientific notation.
>
>How do I prevent AS turning large integers into mush that the shell
script
>does not like?
>
>FYI, I'm just doing do shell script "date -r [some value for epoch
seconds]
>'+%Y-%m-%d'"
>
>What I'm using this for is starting with today's date and generating
dates
>(format YYYY-MM-DD) back for each of X dates prior.
>
>I.e.,
>
>2013-04-27
>2013-04-26
>2013-04-25
>2013-04-24
>2013-04-23
>...
>2013-03-31
>2013-03-30
Perhaps something like this:
set n to "1157445071"
set X to "28"
do shell script "for ((i=0 ; i<=" & X & " ; i++)) ; do date -r $( echo " & n & "-86400 * $i | bc ) '+%Y-%m-%d' ; done"
Or in Applescript:
set today to (current date)
set theDates to {}
repeat with X from 0 to 28
set {year:y, month:m, day:d} to (today - X * 86400)
tell (y * 10000 + m * 100 + d as text) to set end of theDates to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8
end repeat
return theDates
Or this hack still works in Snow Leopard!:
set today to (current date)
set theDates to {}
repeat with X from 0 to 28
set end of theDates to text 1 thru 10 of ((today - X * days) as «class isot» as string) -- NB. 'as string', not 'as text'.
end repeat
return theDates
NG
_______________________________________________
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