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.


In reply to Re: find weekdays for a year by zek152
in thread find weekdays for a year by fionbarr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.