Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Julian Date to Calender date conversion. Please help!

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!)

date_from_yday()
{
perl -e '
use Time::Local;

$yr = $ARGV[0] - 1900;
$yday = $ARGV[1];
$mytime = timelocal(1,0,0,1,1,$yr);
$mytime += ( 86400 * $yday );
($sec,$min,$hour,$day,$mon,$yr,$wday,$yday,$whocares) =
localtime($mytime);
$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.

Thanks

Charanya  
MillerH (Programmer)
30 Sep 11 21:17
The following will get you part of the way there.  You'll still have to do the parsing and potentially install the DateTime module on your system:

CODE

use DateTime;

use strict;
use warnings;

my $dt = DateTime->new(
    year    => 2011,
    month    => 1,
    day     => 1,
);

$dt->add(days => 266);


print $dt->strftime("%b %d, %Y");

# Prints Sep 24, 2011

- Miller

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close