Calculate Days Since 1/1/1970
How can you calculate the number of days since 1/1/1970? This is for updating the shadowLastChange attribute on OpenLDAP.
Is there a way to do this using the linux date command?
ring0 beat me by a few seconds, but the full command is:
echo $(($(date --utc --date "$1" +%s)/86400))
This goes by UTC time. Result:
root@hostname:~# echo $((`date --utc --date "$1" +%s`/86400))
14984
A quick check with WolframAlpha shows that this is the correct value.
I think this is the simplest method:
expr $(date +%s) / 86400
The date
command can give you the number of seconds since 1970-01-01 00:00:00 UTC
.
date +"%s"
You can divide the result by 3600*24
to get the number of days (UTC).
E.g. in Bash
x=`date +"%s"` ; echo $(( $x / 3600 / 24 ))
to display the number of days.