Reputation: 1617
How do you get the date from year and day of year using Date::Calc
?
I managed to figure it out using DateTime
but I need to use Date::Calc
.
The following works, but I don't know how to get it working using Date::Calc
.
use DateTime;
my $dt = DateTime->from_day_of_year(
year => 2018,
day_of_year => 70,
);
# Prints the correct date of March something.
print($dt->strftime('%Y-%m-%d') . "\n");
What I have so far is
use Date::Calc 'Add_Delta_Days';
my $dt = Add_Delta_Days(2018, 70);
Upvotes: 1
Views: 288
Reputation: 385917
The documented usage is
($year,$month,$day) = Add_Delta_Days($year,$month,$day, $Dd);
So
my ($y,$m,$d) = Add_Delta_Days(2018,1,1,70-1);
Note that the 70th day is 69 days after the 1st, thus the use of 70-1
.
Upvotes: 4