comparing two times

Hi Good Morning all,

I have two dates and times in the beloe format.

  1. 07/18/2009 03:45:49
  2. 07/18/2009 03:46:41

i will grep these values from a file. Now my problem is i need to find out whether the second valus is bigger thatn the 1 value. How to compare the times. Please help me in this.

Thanks in advance.

Raju

Hint:convert time in sec or min then compare

#!/bin/ksh93

date1="07/18/2009 03:45:49"
date2="07/18/2009 03:46:41"

if (( $(printf "%(%s)T" "$date1") < $(printf "%(%s)T" "$date2") ))
then
    echo "date2 is after date2"
else
    echo "date2 is not after date1"
fi

Hi Thanks for the reply.

I got a little problem with the code.
i wrote the command you gave to me. but while i am trying to ececute to the script if says the syntax errro. and the line number it shows is the line where IF condition is there. Please help me in this.

What shell are you using?