Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)!

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

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

share|improve this answer

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

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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