Hi all,
i have used the search already before someone shouts at me and i have seen the 'datecalc' program but this is not working correctly for me in the shell and environment i am using.
I am using solaris 10 and bourne shell.
I have two dates '07-04-2009' and '05-05-2009'. I just need to know when the number of days exceeds 90 between two dates.
i.e.
num_days='07-04-2009' - '05-05-2009'
if [ $num_days -gt 90 ]; then
do action....
fi
I can do it in Perl but this doesnt handle leap years etc:
epoch()
{
perl -e '
use Time::Local;
$fmt = "%s"; # %s = seconds in epoch
$mday = substr("$ARGV[0]", 6, 2);
$mon = substr("$ARGV[0]", 4 ,2);
$year = substr("$ARGV[0]", 0 ,4);
$time = timelocal(0,0,0,$mday,$mon,$year);
print int $time;
' "$1"
}
date1=$( epoch '070709' );
date2=$( epoch '070809' );
diff=$(( $date1 - $date2 ))
if [[ $diff -gt 7776000 ] ; then
do action....
fi