Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Gettting the last Friday of every month using Time::Piece

by Jim (Curate)
on Jul 01, 2014 at 21:07 UTC ( [id://1091910]=note: print w/replies, xml ) Need Help??


in reply to Re: Gettting the last Friday of every month using Time::Piece
in thread Gettting the last Friday of every month using Time::Piece

Here's my refactored version of your demonstration script:

use strict; use warnings; use Time::Piece; my $year = shift @ARGV || 2014; my $p = '%Y/%m/%d'; # strptime() format my $f = '%a %b %d %Y'; # strftime() format my $t = Time::Piece->new(); for my $month (1 .. 12) { # Compute the last day of the month... my $monthLastDay = $t->strptime("$year/$month/1", $p)->month_last_day(); # Compute the day of the week of the last day of the month (Sunday + = 1)... my $weekDay = $t->strptime("$year/$month/$monthLastDay", $p)->wday(); # Compute the day of the last Friday of the month (Friday = 6)... my $lastFridayDate = $monthLastDay - (($weekDay - 6) % 7); # Compute the last Friday of the month... my $lastFriday = $t->strptime("$year/$month/$lastFridayDate", $p)->strftime($ +f); print "$lastFriday\n"; } exit 0; __END__ Fri Jan 31 2014 Fri Feb 28 2014 Fri Mar 28 2014 Fri Apr 25 2014 Fri May 30 2014 Fri Jun 27 2014 Fri Jul 25 2014 Fri Aug 29 2014 Fri Sep 26 2014 Fri Oct 31 2014 Fri Nov 28 2014 Fri Dec 26 2014

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1091910]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-20 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found