A note of warning:
$ date -r ~/a
Sun 28 Oct 23:12:00 GMT 2012
$ LC_ALL=C date -r ~/a
Sun Oct 28 23:12:00 GMT 2012
As output, date
outputs the date in the user's local format. As input to -d
GNU date
is more picky on the format though:
$ date -d "$(date -r ~/a) - 1 day"
date: invalid date ‘Sun 28 Oct 23:12:00 GMT 2012 - 1 day’
Fixing locale to C fixes that issue:
$ export LC_ALL=C
$ date -d "$(date -r ~/a) - 1 day"
Sun Oct 28 00:12:00 BST 2012
But note how the date is still 2012-10-28, though now in summer time. That's because 24 hours before that date in Britain, we were still the same day.
Now, if you want the day before, you'd have to write it:
date -d "$(date -r /tmp/file.ref +'%F -1 day')" +%F
date
s withLC_ALL=C
). That may not work as you want around daylight saving time change. – Stéphane Chazelas Aug 28 '13 at 13:38LC_ALL=C
at top in script, is that enough ? actually I didn't understood why useLC_ALL=C
. http://paste.ubuntu.com/6036642/ – Rahul Patil Aug 28 '13 at 13:44