The below scripts shows output number of days between two days. there are different format are below,
%s seconds
-d option to convert the input string into date format as shown below.
Seconds :
echo $(( ( $(date -ud '2015-10-01 10:10:10' +'%s') - $(date -ud '2015-09-10 10:10:10' +'%s') ) )) seconds
1814400 seconds
Minutes :
echo $(( ( $(date -ud '2015-10-01 10:10:10' +'%s') - $(date -ud '2015-09-10 10:10:10' +'%s') )/60 )) minutes
30240 minutes
Hours :
echo $(( ( $(date -ud '2015-10-01 10:10:10' +'%s') - $(date -ud '2015-09-10 10:10:10' +'%s') )/60/60 )) hours
504 hours
Days:
Calculate days in different format:
echo $(($(($(date -d "2010-06-01" "+%s") - $(date -d "2010-05-15" "+%s"))) / 86400))
17
echo $(($(($(date -d "Oct 10" "+%s") - $(date -d "sep 2" "+%s"))) / 86400))
38
Comments (0)