Re: quick way to get yesterdays date

From: Martin Schmitt (martin@SCHMITT.LI)
Date: Tue Aug 05 2003 - 12:13:23 EDT


Hallo Shawn Bierman,
dear Shawn Bierman,

* BiermanS@METHODISTHEALTH.ORG wrote/schrieb:

> I tried something like this but if todays date is 05 it will return 4
> instead of 04. Is there an existing method for doing this that I have
> overlooked?

You've also overlooked that this will proably return 0 on the 1st.

> DDATE=`date +%d`
> DDATE=$((${DDATE} - 1))
> echo ${DDATE}

Here's a somewhat unorthodox but robust approach that I'm quite happy with:

perl -MPOSIX -e 'print strftime("%d.%m.%Y", localtime(time()-86400))."\n";'

86400 is the number of seconds on one day (so you can, for example, see
what date it was 6 hours ago), and the output format can be easily modified
using the well-known strftime macros.

-martin

--
Busier than a one-legged man in an ass-kicking contest.


This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:17:07 EDT