On 2018-04-09, Paul de Weerd <we...@weirdnet.nl> wrote:
> On Sun, Apr 08, 2018 at 11:12:43PM -0700, Philip Guenther wrote:
>| On Sun, Apr 8, 2018 at 10:54 PM, Robert Klein <rokl...@roklein.de> wrote:
>| 
>| > this works for me:
>| >
>| > date -r $(( $(date +%s) - 1 * 24 * 60 * 60 )) +%Y_%m_%d
>| >
>| 
>| Did you test that after 11pm on the day when daylight-saving time ends and
>| the clock is turned back, resulting in a 25 hour long day?
>
> For those special occassions there's:
>
> date -j `date +%Y%m%d1200` +%s
>
> Turning this into:
>
> date -r $(($(date -j `date +%Y%m%d1200` +%s) - 86400)) +%Y_%m_%d
>
> Less perl (and less typing) at the expense of a total of 3 invocations
> of date.  Although I loathe the natural language parsing options built
> into Linux date(1), this sort of thing is rather convenient.
>
>| I would use this:
>|    perl -MPOSIX=strftime,mktime -le '@d=localtime(); $d[3]--; mktime(@d);
>| print strftime("%Y_%m_%d",@d)'
>| 
>| Philip Guenther
>
> Paul 'abolish DST now' de Weerd

The time I usually need yesterday's date is when constructing a filename
for things like log files or mailboxes that have been rotated in a job
run overnight, often in monthly.local.

For this, I just cheat and set a timezone that is a bit behind...
`date -z US/Pacific +%Y-%m-%d`

Obviously no good if your timezone is within a couple of hours east of
the date line...


Reply via email to