Wednesday, 12 March 2008

Shell script Get the time difference

Get difference

date1=`date +%s`
date2=`date +%s`
date -d "00:00:00 $(( ${date2} - ${date1} )) seconds" +"%H:%m:%S"


barun said...

Wow! I never knew we could use our good ol' date command in this way!

Anonymous said...

Very nice, except if you are working with Solaris :(

Anonymous said...

For Sun/Solaris: just put /usr/local/bin before the date command to use GNU date...