compare dates using shell sript

I have 2 date feilds

2011-05-13:18:45
2011-05-13:18:30

I need to compare them and say its OK/NOK

I tried this but dint work.

systime=2011-05-13:18:45
shubtime=2011-05-13:18:30
if [ "$systime" -eq "$shubtime" ]
then
         echo" OK"
else
         echo "NOK"
fi

In this its not same so the o/p should be NOK

ksh
systime=2011-05-13:18:45
shubtime=2011-05-13:18:45
echo $systime $shubtime | tr -d ':-' | read a b
[[ $a -eq $b ]] && echo OK || echo KO
1 Like

If they must be exactly the same

systime=2011-05-13:18:45
shubtime=2011-05-13:18:30
if [ "$systime" = "$shubtime" ]
then
    echo" OK"
else
    echo "NOK"
fi

Or shorter:

[ "$systime" = "$shubtime" ] && echo" OK" || echo "NOK"

PS: please use code tags and indent your code

1 Like