[TriLUG] Some script help
Alan Porter via TriLUG
trilug at trilug.org
Tue May 12 16:40:43 EDT 2015
> Bash is fine for this, but the key is to not try to compare dates. Bash doesn't do that well at all.
If you must compare dates in bash, let the date command convert them for
you.
echo $(( ( $(date -d '2015-05-12' +%s) - $(date -d '2014-05-12'
+%s) ) / 86400 ))
365
Or if long lines are not your thing...
d1=$(date -d '2015-05-12' +%s)
d2=$(date -d '2014-05-12' +%s)
echo $(( ( $d1 - $d2 ) / 86400 ))
365
Alan
More information about the TriLUG
mailing list