Your question is a little confusing, you ask how to get the first day of the month and then cut-and-paste Date::Calc instructions on figuring out the first Monday of a week. If you want the first day of the month, simply refer to is with the number '1'. No Data::Calc required, that's always the first day.

Now how to figure the first Monday of a given month? It takes a little logic, what the Date::Calc instructions are explaining is how to get the Monday of any given week, now if you want the first Monday of the month you should check Monday_of_Week() of the first day of a month. If the result is in the same month, you got lucky and Monday falls on the first, if not, increment the week of the year by 1 and you will have your answer.

#$year, $month, and $day are set to the first of any given month my ($week,undef)=Week_of_Year($year,$month,$day); my (undef, $tmpmonth, $firstmonday)=Monday_of_Week($week,$year); if ($tmpmonth != $month) { (undef, undef, $firstmonday)=Monday_of_Week(++$week,$year); } #$firstmonday now contains the date of the first Monday of a given mon +th. #Put this in a loop or a sub or whatever and you can call it with argu +ments. print "First monday of $month/$year is $firstmonday\n";

In reply to Re: getting the First day of the month by pzbagel
in thread getting the First day of the month by Anonymous Monk

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.