Using the excellent Perl DateTime module it is trivial to obtain the year and week number for a date, but going the other way seems to be a bit more difficult. How does one go about obtaining a date starting with the year and week number?
Here's one way to do it using only DateTime:
use DateTime;
sub first_day_of_week
{
my ($year, $week) = @_;
# Week 1 is defined as the one containing January 4:
DateTime
->new( year => $year, month => 1, day => 4 )
->add( weeks => ($week - 1) )
->truncate( to => 'week' );
} # end first_day_of_week
# Find first day of second week of 2012 (2012-01-09):
my $d = first_day_of_week(2012, 2);
print "$d\n";
Try:
use Date::Calc qw(:all);
my $year = 2012;
my $week = 14;
my ($year2, $month, $day) = Monday_of_Week($week, $year);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With