How to find the difference in days between two dates?

Tree picture Tree · Feb 9, 2011 · Viewed 184.6k times · Source

A="2002-20-10"
B="2003-22-11"

How to find the difference in days between two dates?

Answer

techjacker picture techjacker · Aug 4, 2011

The bash way - convert the dates into %y%m%d format and then you can do this straight from the command line:

echo $(( ($(date --date="031122" +%s) - $(date --date="021020" +%s) )/(60*60*24) ))