Is there a way to compare two different dates in a shell?

Here is an example of how i would like to use this, though it does not work as-is.

todate=2013-07-18
cond=2013-07-15

if [ $todate -ge $cond ];
then
    break
fi

What should i do to get the desired result?

Best Answer


The right answer is still missing

todate=$(date -d 2013-07-18 +%s)
cond=$(date -d 2014-08-19 +%s)

if [ $todate -ge $cond ];
then
    break
fi

Note that this requires a gnu date The equivalent date syntax for BSD date (like found in OSX by default) is date -j -f "%F" 2014-08-19 +"%s"