shell - How to subtract two different date formats to get days in bash? -


i working on bash. have subtract current date given date number of days difference. given date in format m/d/yyyy instead of 09/26/2015 9/26/2015. if try convert both dates same format , subtract says invalid date format.

           date1=$(date +"%f")            date2=$(date -d 11/2/2015 +"%f")            diff=$(date "--date=${date2} -${date1}" +%f)            echo $diff days remaining 

this had tried variations, doesn't work. doing wrong? in advance.

try this:

let diff=(`date +%s -d 11/2/2015` - `date +%s`)/86400 echo $diff days remaining 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -