I want to get the date +%m/%d/%Y
a different number of days ago.
$(( $(date +%s)- 259200))
gives me the seconds of 3 days ago. The -d
parameter doesn't accept the seconds to parse it in the format I want 05/06/2011 (error message: date: invalid date '1307284916'
).
Is there a way to get date
to work?
On MacOS X, you can use
date -r 1307284916 +%m/%d/%Y
to get the result you want. If you are not on a BSD-derived system like MacOS X (e.g. if you are using Linux), there doesn't seem to be a simple analogue ofdate -r
. And traditional versions of Unix usually don't even provide the facilities of GNU'sdate
.If you get really stuck, contact me (see my profile) for a program
timestamp
:To get date on linux to accept a simple timestamp for -d, prefix the number with the @ sign!