Could somebody recommend a small utility to calculate the number of days between two dates?

Werner Schram wrschram at
Sun Jan 31 19:17:48 UTC 2010

On 01/31/2010 06:46 PM, Peng Yu wrote:
> Could somebody let me what tool I can use to calculate the number of
> days before two dates in ubuntu?
This one only works in bash:

echo $(((`date +%s -d "jan 31 00:00:00 UTC 2010"`-`date +%s -d "jan 30 
00:00:00 UTC 2010"`) / 86400))

Replace the two dates with the wanted dates, and it calculates the 
number of seconds between those. I used UTC on purpose because that 
timezone doesn't have daylight saving. I expected it to fail on leap 
seconds, but it doesn't. It can be rewritten to use bc to make it work 
on other shells, but this might already be good enough.


More information about the ubuntu-users mailing list