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
Post a Comment