Linux – How to get the difference between two dates under bash

bashdatelinux

Exactly as the question sounds.
I want to subtract say 20120115 from 20120203 and get 19 as the answer.
What is the best way to implement this in a shell script?

Best Solution

let DIFF=(`date +%s -d 20120203`-`date +%s -d 20120115`)/86400
echo $DIFF