Compare two dates using Shell Programming

Hi all,

a=2007-05-10 (YYYY-DD-MM Format)
b=2007-06-10

These are the two given dates and I need to compare.
(First It should split the dates into YYYY,dd,mm)

The script should first compare years(2007 here).If both are same or if "a" is lesser than "b"(ie.suppose year in "a" is 2006),it should print correct.If "a"(ie. suppose year in a is 2008) is greater than b,then it should print error.Similarly for the dates(05 and 06).

No need to check for the months(10).

Regards,
Dave Nithis.

this might be useful

convert the dates to a long integer (ksh) and then subtract

#!/bin/ksh
 a="2007-10-27"
 b="2006-03-22"
if [[ $((  $(echo $a | tr -d '-')   -  $(echo $b | tr -d '-')  )) -ge 0 ]] ; then
   print "correct"
else
   print "failure"    
fi


in bash you could do
(( ${a:0:4} <= ${b:0:4} )) && echo true || echo false
or if you want to check year AND day
(( ${a:0:4} <= ${b:0:4} && ${a:5:2} <= ${b:5:2} )) && echo true|| echo false

Can you explain the if part?