Last monday of each month Perl
Hello LQ,
I am new to Perl scripting and have completed a Perl script. The final part of the script needs to find the last Monday of each month. So if it is August, the script returns 20110829. Does anyone have any idea how to accomplish this via Perl? Thanks for any help. |
I'm not aware of any "ready-made" way to do it.
Suggestion: write your own function that will: 1. Get specified day/month date value of the last day of the month (e.g. "sep 30 2011") 2. Get day-of-week of that date value 3. Subtract backwards to the preceding Monday 4. Return that (monday's) date value |
Quote:
|
With thousands of Perl Modules available I am sure you can find something similar in good datetime manipulation module.
Assuming you are using Linux if you cal call one liner shell script from perl here it is: Just tested for Sep-11 and Oct-11. Code:
$ cal -m 9 2011 | cut -c1-2 | sed "/^$/d" | tail -n 1 |
Actually, Sergei Steshenko made an *excellent* suggestion. I'd encourage you to check out the date/time manipulation tools available at the link he gave you!
IMHO .. pSM |
All times are GMT -5. The time now is 09:40 AM. |