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)!
Asked
Active
Viewed 2,356 times
2 Answers
3
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.

Eduardo Ivanec
- 14,881
- 1
- 37
- 43
1
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

glenn jackman
- 4,630
- 1
- 17
- 20