Re: find yesterday date using date command
Re: find yesterday date using date command
- Subject: Re: find yesterday date using date command
- From: "Mark J. Reed" <email@hidden>
- Date: Tue, 2 Jan 2007 07:37:40 -0500
On 1/2/07, Hung Phan <email@hidden> wrote:
The below command will give yesterday date. I tried to truncate the
result down to the date only with:
> do shell script "date +%a $(date -r $(( $(date +%s) - 86400 )))"
Doesn't seem to work. Am I missing something or is that even possible
with 3 variables inside "date" command?
No, you just need to add the +%a as an argument to the same date
command that has the -r:
do shell script "date -r $(( $(date +%s) - 86400 )) +%a"
Here's how it works. First, the shell runs the inner date command and
replaces the $(...) with its output. The +%s tells date to output the
seconds since the epoch, which is as I type this 1167741115. So after
that step, the command looks like this:
"date -r $(( 1167741115 - 86400 )) +%a"
Next the shell replaces the $((...)) with the result of evaluating the
arithmetic expression inside, in this case a simple subtraction:
"date -r 1167654715 +%a"
Now there's a single command with no more shell substitutions, which
is just executed. The -r tells the command what date to output, and
the %a tells it how to output it.
Except I don't think %a is what you want, since that just gives you
the day of the week. You probably want something like %F, which
outputs "2007-01-01".
Again thank you very much for all the responses,
On Jan 1, 2007, at 4:12 PM, Mark J. Reed wrote:
> The OP did ask for how to do this with the "date command"; assuming
> that the shell command date(1) was actually intended, the result may
> be achieved thus:
>
> do shell script "date -r $(( $(date +%s) - 86400 ))"
>
> Although if you have the GNU coreutils package installed (e.g. in
> /sw/bin/ via fink, or in /opt/local/bin via MacPorts), it's a little
> easier:
>
> do shell script "/sw/bin/date -d yesterday"
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (applescript-
> email@hidden)
> Help/Unsubscribe/Update your Subscription:
> 40canby.k12.or.us
> Archives: http://lists.apple.com/mailman//archives/applescript-users
>
> This email sent to email@hidden
--
Mark J. Reed <email@hidden>
_______________________________________________
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/mailman//archives/applescript-users
This email sent to email@hidden