Re: Epoch Seconds to YYYY-MM-DD
Re: Epoch Seconds to YYYY-MM-DD
- Subject: Re: Epoch Seconds to YYYY-MM-DD
- From: Jon Pugh <email@hidden>
- Date: Sat, 27 Apr 2013 09:19:40 -0700
On Apr 27, 2013, at 8:25 AM, Marconi wrote:
> 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?
AppleScript uses a 31 bit integer for most numbers, and if your number won’t fit, it’s promoted to a float. As such, you’ll need to manage larger numbers yourself.
> 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.
The simplest thing is to keep separate pieces.
> I thought I'd just get the epoch seconds for today and iterate through a loop, subtracting 86,400 from the original epoch seconds and converting each to YYYY-MM-DD format with the shell script.
Here’s how I’d do it in pure AppleScript.
Jon
set d to current date
repeat 30 times
log formatDate(d)
set d to d - 1 * days
end repeat
on formatDate(somedate)
set y to year of somedate
set m to month of somedate as integer
if m < 10 then set m to "0" & m
set d to day of somedate
if d < 10 then set d to "0" & d
set s to (y & "-" & m & "-" & d) as string
end formatDate
_______________________________________________
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