comparing dates

Hi guys

I have a a variable called check_ts which holds a date value. this date value keeps refreshing every 15 minutes.

I am going to start a cron job 5 minutes after the refresh. I have to check if the current date > 20 min of check_ts. how do i do that.

thanks
ragha

the value of check_ts is like this

10/24/2006 3:15:47 PM

cal_days

#!/bin/perl
use Time::Local;
my $month=shift;
my $day=shift;
my $year=shift;
my $hour=shift;
my $min=shift;
my $sec=shift;
my $var=shift;
if ( "\u$var" =~ /PM/ )
{       $hour=$hour+12; }
my $time = timelocal(sec,min,hour,$day,$month-1,$year-1900);
my $time1 = timelocal(localtime());
my $days = ( $time1-$time ) / 60;
printf("%f", $days);
cal_days `echo $check_ts | sed -e "s/\// /g" -e "s/:/ /g"`

anbu

thanks a lot for the reply. is cal_days a seperate file. how do i invoke it and where do i implement my logic for checking if the current time is greater than 20 min or not. my shell script knowledge is very poor.

thanks

tm=$(cal_days `echo $check_ts | sed -e "s/\// /g" -e "s/:/ /g"`)

if [ $tm -ge 20 ]
then
   echo "greater than or equal"
else
   echo "lesser"
fi

thanks a lot anbu.

is cal_days a file with .pl extension. where should i save that file. how will i invoke it as a function in my current file. pls elaborate on this. i appreciate your help. thanks again.

is cal_days a file with .pl extension
No extension is required

where should i save that file
Save that file wherever you want to keep. If it is not in the same directory of your script then include the path.

how will i invoke it as a function in my current file
Its like another shell script. You can call as shown above.

thanks anbu

I implemented as you said. I got the following error

Month '24' out of range 0..11 at cal_days line 12

Thanks
Ragha

#!/bin/perl
use Time::Local;
my $day=shift;
my $month=shift;
my $year=shift;
my $hour=shift;
my $min=shift;
my $sec=shift;
my $var=shift;
if ( "\u$var" =~ /PM/ )
{       $hour=$hour+12; }
my $time = timelocal(sec,min,hour,$day,$month-1,$year-1900);
my $time1 = timelocal(localtime());
my $days = ( $time1-$time ) / 60;
printf("%f", $days);

I think you have changed the format of the variable check_ts.

hi anbu

i now get an error like this

Month '-1' out of range 0..11 at cal_days line 12

can you show the value of variable check_ts?

hi this is the value of the variable

10/25/2006 1:56:42 PM

Its working for me. If you have the above value in the variable then it should work.
can you show the trace of your script?

i get the date from a table using this script

cur_time=`sqlplus -s batch_user/batch_user@$SIEBEL_DB_ORACLESID << EOF0 
set heading off
SET FEEDBACK OFF
SET PAGESIZE 0
SET LINESIZE 900
select created from FusionHC_Job_State
  where created = (select max(created) from FusionHC_Job_State);
EOF0`

Then i do this in original script

tm=$(cal_days `echo $cur_time | sed -e "s/\// /g" -e "s/:/ /g"`)

if [[ $tm -gt 20 ]]
then
exit
fi

I get this error in original script


Month '-1' out of range 0..11 at cal_days line 12

when did echo $cur_time, i got this

25-OCT-06 as the value. but the value in the table does not look like this. i dont know why..

use to_char function to get the date in the above format

where should i use the to_char function. in shell script or when querying tables.

i get the correct result while normally querying the database

use the to_char function in sql query