in reply to How to find first day of the first week on the month?
G'day devbond,
"i need to find the first day of the first week of a month."
Firstly, that seems an odd way to ask this. I'm assuming, for a given year and month, you want to know what day (e.g. Sunday) the 1st of that month is. If that's not what you meant, please clarify.
There's a plethora of modules on CPAN that can do this type of thing; however, the builtin module, Time::Piece, can also do this and you already have it installed. So, unless you're already using some Date::*, Time::*, etc. module, Time::Piece is probably your best choice. Here's sample code:
#!/usr/bin/env perl -l use strict; use warnings; use Time::Piece; # In 2 days it will be Tuesday, 1st October 2013 my $month = 10; my $year = 2013; my $day_name = Time::Piece->strptime("$year$month" . '01', '%Y%m%d')-> +fullday; print "01-Oct-2013 is a $day_name";
Output:
01-Oct-2013 is a Tuesday
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to find first day of the first week on the month?
by BillKSmith (Monsignor) on Sep 29, 2013 at 00:10 UTC | |
by kcott (Archbishop) on Sep 29, 2013 at 07:01 UTC | |
|
Re^2: How to find first day of the first week on the month? ( strptime %Y-%j time-piece-firstlastofeverymonth.pl)
by Anonymous Monk on Sep 28, 2013 at 23:42 UTC |