charanya (Programmer) (OP)
30 Sep 11 20:44
I am new to Perl, I am trying to convert Julian date to calendar date (day of the year). For example, 26711 corresponds to 24-Sep-2011. I tried two approach to this, none being successful.
1) I saw this code online, but this code returns wrong date. This code does not return 24-Sep-2011, instead returns 26-Sep-2011 (Which is wrong!)
perl -e '
$yr = $ARGV - 1900;
$yday = $ARGV;
$mytime = timelocal(1,0,0,1,1,$yr);
$mytime += ( 86400 * $yday );
$yr += 1900;
printf("%02d/%02d/%d\n", $day, $mon, $yr);
' $2 $1
date_from_yday 267 2011
2) I tried connecting to oracle db and fetch the date.
$RETVAL=`"select to_date(nvl(SUBSTR(126711 , 2 , 5) , '00179'), 'DDDYY') from dual" | $ORACLE_HOME/bin/sqlplus -L -S $CONNECT_STRING`;
This gives me error saying "select to_date(nvl(SUBSTR(126711 , 2 , 5) , '00179'), 'DDDYY') from dual : not found". I know the connection string is correct because that is used by other queries in the script.
Any help is appreciated. If there is a new approach to it, i can try that too. Please help ASAP.