Date and time difference

I have start and finish date in the following format -

Start Date: 5/21/2010 9:14:00 AM
End Date : 5/24/2010 7:23:00 AM

I need to get the time difference in the following format [hh]:mm or [mm]. Any help would be really appreciated.

Thank you!

If you have GNU date

$ D1="5/21/2010 9:14:00 AM"
$ D2="5/24/2010 7:23:00 AM"
$ DM=$((($(date -d "$D2" +%s)-$(date -d "$D1" +%s))/60))
$ printf "%s:%02d\n" $((DM/60)) $((DM%60))
70:09
1 Like

set a=3
set D1="5/21/2010 9:14:00 AM"
set D2="5/24/2010 7:23:00 AM"
set DDM=$((($(date -d "$D2" +%s)-$(date -d "$D1" +%s))/60))
Variable syntax
printf "%s:%02d\n" $((DDM/60)) $((DDM%60))
Variable syntax

why not working

The code was for bash/ksh not csh

In csh you'll need something like this:

set a=3
set D1="5/21/2010 9:14:00 AM"
set D1S=`date -d "$D1" +%s`
set D2="5/24/2010 7:23:00 AM"
set D2S=`date -d "$D1" +%s`
set DDM=`expr  \( $D2S - $D1S \) / 60`
printf "%s:%02d\n" `expr $DDM / 60` `expr $DDM % 60`