in reply to find weekdays for a year

For future reference you should show the things that you have tried. We aren't a code-writing service.

That being said you should look at Date::Simple. What you want to do is find the first thursday of a year. Date::Simple uses Sunday as the 0th day of the week so Thurs is the 4th. I used Date::Calc because it was on my computer already.

use Date::Calc qw(:all); $count = 0; #insert your own year. $year = "2011"; #set $date to the first day of the year @date = ($year,1,1); print Date_to_Text(@date) . "\n"; #find the next thursday if(Day_of_Week(@date) > 4) { @date= Add_Delta_Days(@date,7-Day_of_Week(@date)+4); } else { @date=Add_Delta_Days(@date,4-Day_of_Week(@date)); } #now you have the first thursday. Now just count how many #until you reach a new year while(@date[0] eq $year) { $count++; @date=Add_Delta_Days(@date,7); } print "$count thursdays in $year\n";

You should probably verify that the results are correct. They seem to make sense to me but that doesn't mean much. Hope this helps.

Replies are listed 'Best First'.
Re^2: find weekdays for a year
by fionbarr (Friar) on Jul 19, 2011 at 13:51 UTC
    found this...thanks
    1 use strict; 2 use warnings; 3 4 use DateTime::Event::Recurrence; 5 6 7 my $dt1 = new DateTime( year => 2011 ); 8 my $dt2 = new DateTime( year => 2012 ); 9 my $der = DateTime::Event::Recurrence->weekly(days=>4); # + Thursday is #4 10 print $_->ymd, ' ', ,$/ for 11 $der->as_list( start => $dt1, end => $dt2 );