That's tricky because of the ambiguity of what is meant by the first week of the month. Do you want to count partial weeks too? For example, if the month starts on a Monday (instead of a Sunday), do you want to count that first Monday-Saturday to be the first week? And if you do, will you also count months that start on a Thursday as having their first week be Thursday-Saturday?.... ...and, if you do, what if the first day of the month is a Saturday? Does that mean that week one of the month consists of one day only?

Once you work out the details that define the problem, you'll be well on your way to working out the details of implementing the solution.

And you also have to consider whos calendar you're using. When I worked for one corporation, the "Fiscal" calendar was quite different from the traditional calendar. We were on what we called a "4-5-5-4" schedule, meaning the "Months" all had exactly 4 or 5 weeks in them; exactly. Fiscal months always started on Sunday, and always ended on Saturday, no matter what the traditional calendar said. And that meant that June, for this corporation, might not be over until some time in the first week of what the rest of the world called July.

I've looked at Date::Manip and see that, though it does provide a Week-of-the-year function, it doesn't offer week-of-the-month. However, once you define your problem more tightly, you might have success using the Date_WeekOfYear() function and counting back to the first of the current month.


Dave


In reply to Re: Getting the current week number by davido
in thread Getting the current week number by slloyd

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.