Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!
  • Students Click Here

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Julian Date to Calender date conversion. Please help!

Julian Date to Calender date conversion. Please help!

Julian Date to Calender date conversion. Please help!

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 '
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) =
$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.



RE: Julian Date to Calender date conversion. Please help!

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:


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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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!

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