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!

*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.


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 Calculator from YYYY-MM-DD

Julian Date Calculator from YYYY-MM-DD


I am trying to write a script to calculate the Julian date of the year from the given string which is of the format "YYYY-MM-DD". Can someone help me out here. I am at a lost after going through all the various Date::Calc modules and nothing seems to work for me. Can someone be kind enough to help me out in this!

Thanks very much

RE: Julian Date Calculator from YYYY-MM-DD

I too failed to find a Perl solution but I got round the problem by populating a MySQL database with all the date details for the previous 5 years and the next 14 years.
Using MySQL queries allows any date calculations to be carried out.
A flat file would also work but would require more processing.
Just a suggestion which works for me.


RE: Julian Date Calculator from YYYY-MM-DD

Really? A simple google turned up an old FAQ with a perl sub and the module DateTime::Calendar::Julian, both look suited to the task. Something wrong with these?

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo

RE: Julian Date Calculator from YYYY-MM-DD

I have already seen this. I think I did not pose the correct question. It should have been the other way round. I.e. to calculate the date from the julian date!

So if the julian date is 13, it should prompt me the date corresponding to this julian date i.e. 2006-01-13.

The perl sub gives the opposite. If you know how to reverse this I will be grateful for that!

RE: Julian Date Calculator from YYYY-MM-DD

Seems to be some confusion here. "Julian Date" has several radically different meanings, according to . Do you mean you want the yyyy-mm-dd corresponding to a specified nth day of the year? If so, you could use something like:


use POSIX;
print "$ymd\n";

RE: Julian Date Calculator from YYYY-MM-DD

Sorry, that should have been:


RE: Julian Date Calculator from YYYY-MM-DD

Tony, might not be a bad idea to retrofit that into Date::Manip, with the authors permission of course ;)

Spend an hour a week on CPAN, helps cure all known programming ailments

RE: Julian Date Calculator from YYYY-MM-DD

Hey Tony,

Thanks for the tip. However when I execute your statement, It is returning $ymd as 2006-02-19!. Is there some numbers to be changed inorder to get the correct julian date.

Yes I mean the julian day for the year. Hence for today, (2006-01-16), the julian day is 16.

RE: Julian Date Calculator from YYYY-MM-DD

all arrays should be 0-based, so that should be accounting for at least two of the missing $days--, the other one ... $ymd[4]+1, dunno, but that could be it ...

Spend an hour a week on CPAN, helps cure all known programming ailments

RE: Julian Date Calculator from YYYY-MM-DD

This is roughly the same as Tony's code except shoved into a sub.  I tried to avoid changing the date values around except where necessary.


print "16th Day: ", DOY_to_YMD(16), "\n";

sub DOY_to_YMD {
    use POSIX;
    my $DoY = shift; # Day of Year
    my ($day, $month, $year) = (localtime)[3..5];
    my $jan1 = POSIX::mktime(0,0,0,0,0,$year);  # Actually Dec 31 of prev year
    my @time = localtime($jan1 + $DoY * 86400);
    return sprintf "%4d-%02d-%02d", $time[5]+1900, $time[4]+1, $time[3];

RE: Julian Date Calculator from YYYY-MM-DD


The test date used in my code was day 50 of 2006, which is 2006-02-19. You would obviously use your own data instead.

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