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.
| [reply] |
| [reply] |
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.)
| [reply] |
perl -e 'use POSIX; my $date=strftime("%w",localtime); print $date;'
Directives(%w) are same as date command. look
"perldoc POSIX" and "info date" | [reply] |
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.
| [reply] |
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
| [reply] |