in reply to Week number of the month

Part of the challenge is how you are defining the week numbering. For example, April 1, 2016 falls on a Friday. So is April, 1, 2016 in week 0? Or is it week 1?

Depending on your needs, you can check out DateTime's week_of_month method, which is described as:

The week of the month, from 0..5. 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.

Here's an example code that displays shows some details (name of day, name of month, week of month) for 40 dates starting with the current date.

use strict; use warnings; use feature 'say'; use DateTime; my $dt = DateTime->now; foreach my $count (1..40) { my $day = $dt->day_name; my $month = $dt->month_name; my $week_of_month = $dt->week_of_month; say "Date/time stamp: $dt"; say " Name of Day: $day"; say " Name of Month: $month"; say " Week of Month: $week_of_month"; say ""; my $dur = DateTime::Duration->new(days => 1); $dt = $dt->add_duration($dur); }

Of course, if that does not match the way that you want to determine which week number of the month that a particular date is in, then you may need to come up with some custom code to better match your needs.