Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: How to find week of the month?
by Zaxo (Archbishop) on Aug 17, 2005 at 08:12 UTC

    You need to agree on some standard for numbering weeks which begin on Monday or Wednesday or Saturday.

    POSIX::strftime has three formats for different ways of numbering week-of-the-year. Week-of-the-month has the same trouble, but more often, and strftime doesn't attempt to cover it. It's a business decision, I suppose.

    After Compline,
    Zaxo

Re: How to find week of the month?
by salva (Canon) on Aug 17, 2005 at 08:38 UTC
Re: How to find week of the month?
by japhy (Canon) on Aug 17, 2005 at 15:26 UTC
    It depends what you mean. Given the calendar:
     S  M  T  W  T  F  S
                 1  2  3
     4  5  6  7  8  9 10
    11 12 13 14 15 16 17
    18 19 20 21 22 23 24
    25 26 27 28 29 30
    
    which "week" is the 12th in? Is it the 2nd or 3rd week? If you count a week as 7 consecutive days, starting with the week of the 1st through 7th, then the 12th is in the second week. If, on the other hand, you can a week as the days Sunday through Saturday, then the 12th is in the third week.

    Please clarify your question, anonymous one, so that we can better direct your efforts.

    Either solution can be devised simply through the use of the standard Time::Local module. (I eschew those everything-but-the-kitchen-sink Date/Time modules.)


    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re: How to find week of the month?
by newroz (Monk) on Aug 17, 2005 at 09:08 UTC
    perl -e 'use POSIX; my $date=strftime("%w",localtime); print $date;'
    Directives(%w) are same as date command. look
    "perldoc POSIX" and "info date"
      That gives the day of the week in range 0 .. 6 with sunday as day 0. Week of of the month isn't available in strftime().

      DateTime has a week_of_month method, which is defined as

      The first week of the month is the first week that contains a Thursday. This is based on the ICU definition of week of month, and correlates to the ISO8601 week of year definition. A day in the week before the week with the first Thursday will be week 0.

      But I can't guess if that's the definition the OP wants.

        Sorry for misunderstood.Yes, you're right.
        sprintf doesn't provide it.
        And there is one more module that provides week of month.
        Date::Handler