Time Difference

Hi Experts...

I want to calculate the time difference between two date-time values (using ksh). It can return the difference in hours (or whatever..)

For eg: time_diff "09/12/2009 12:30" "09/10/2009 12:30" should return 1464 hours...

 
$time_diff "09/12/2009 12:30:00" "09/10/2009 12:30:00"
1464.00
$time_diff "09/12/2009 13:36:09" "09/12/2009 13:30:00"
0.1025

Thanks...
PRKS

Try:

Use 3600, if you need to see in hours. 60 , if you need to se in minutes

echo $var1
09/12/2009 12:30:00
echo $var2
09/12/2009 13:30:00

echo "(`date +%s -d"$var2"` - `date +%s -d"$var1"`)/3600" | bc
1

Hi !
I am using ksh and its giving this error::

 
date: bad format character - s

Please help...

The format option 's' is only available with GNU date, so it's mostly Linux specific. But you might be able to use Perderabos datcalc script with a few adaptions.

Try this link, as there is no quick solutions available in unix.

If you can write script in PERL, then look at this module which can help you in identifying the difference between date: Date::Manip - search.cpan.org