2

I have a date say 2015-12-30. I want to find the day difference between this day and today's date.

Currently I am doing this

dest_date="2015-12-30"
now=`date +%Y-%m-%d`

echo "( `date -d $dest_date +%s` - `date -d $now +%s`) / (24*3600)" | bc -l

But this is giving error as

date: invalid date `+%s'
(standard_in) 1: parse error
Anirban Nag 'tintinmj'
  • 5,572
  • 6
  • 39
  • 59

1 Answers1

2

You can simplify this:

dest_date="2015-12-30"
diff=$(( ($(date '+%s' -d "$dest_date") - $(date '+%s')) / 86400 ))

echo $diff
14
anubhava
  • 761,203
  • 64
  • 569
  • 643