How to print in linux/unix bash the number of days since a specific date till now? (for example days since 23rd of June 2009 till today)!

link|improve this question
In what format is the "first" date? Can we choose? – Bittrance Jun 13 '11 at 11:23
feedback

2 Answers

You can use something like this:

date1=$(date --utc --date "2008-10-20" +%s)
date2=$(date --utc --date "2009-10-20" +%s)
diffdays=$(( (date2-date1)/(3600*24) ))

This assumes date2 is more recent than date1.

Adapted from http://www.unix.com/tips-tutorials/31944-simple-date-time-calulation-bash.html.

link|improve this answer
feedback

I prefer languages with specialized datetime libraries for date arithmetic. For example:

ruby -r date -e 'd = Date.parse(ARGV.shift); p (Date.today - d).to_i' 2010-09-23
link|improve this answer
Is ruby installed by default on OSX? – jftuga Jun 13 '11 at 15:26
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.