Try this: In my example below, it is assuming B is always greater than A. This could be coded to where it doesn't matter as well.
#!/bin/ksh
DATE_A=$(date +%Y%m%d%H%M%S -d "$1")
DATE_B=$(date +%Y%m%d%H%M%S -d "$2")
DATE_C=$(date +%Y%m%d%H%M%S)
if [ "${DATE_C}" -gt "${DATE_B}" ]; then
echo "C, ${DATE_C}, is greater than B, ${DATE_B}"
elif [ "${DATE_C}" -gt "${DATE_A}" ]; then
echo "DATE_C, ${DATE_C}, is between A, ${DATE_A}, and B, ${DATE_B}"
else
echo "C, ${DATE_C}, is less than A, ${DATE_A}"
fi
tests
$./chk_date.ksh "01-JAN-2009 10:20:10" "12-DEC-2009 10:30:00"
C, 20091125051733, is between A, 20090101102010, and B, 20091212103000
$ ./chk_date.ksh "01-DEC-2009 10:20:10" "12-DEC-2009 10:30:00"
C, 20091125051752, is less than A, 20091201102010
$ ./chk_date.ksh "01-JAN-2009 10:20:10" "01-JAN-2009 10:30:00"
C, 20091125051824, is greater than B, 20090101103000
I have to do comparison between two date values. One is current date time (min) and another date (max) will be calculated by adding some input minutes with current date time.
Pls help to get the above requirement.
Ex:
Min_Date=Current Datetime (Format: DD-MON-YYYY HH24:MI:SS)
Max_Date=Current Datetime + X mins (Format: DD-MON-YYYY HH24:MI:SS)
Check out the link provided by Jim McNamara above. It contains links to other solutions as well. If none of these work for you, let me know and I can dig up a function I wrote to do this. That was several jobs ago though and I'm not sure where I have it.