Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to find the last date of the previous month?

by tobyink (Abbot)
on Oct 30, 2012 at 08:11 UTC ( #1001468=note: print w/ replies, xml ) Need Help??


in reply to How to find the last date of the previous month?

In the spirit of TIMTOWTDI, here's an example using Time::Piece. The advantage of using Time::Piece is that as of Perl 5.10, it's bundled with Perl core. (As is its companion module Time::Seconds.)

use 5.010; use Time::Piece; use Time::Seconds qw( ONE_DAY ONE_HOUR ); sub last_day_of_last_month () { my $now = localtime; my $day = Time::Piece->new( $now - ($now->day_of_month * ONE_DAY) ); $day += ONE_HOUR * ($now->isdst <=> $day->isdst); return $day; } say last_day_of_last_month->mdy('/');

The daylight savings calculation is a bit of an annoyance. :-(

Yeah, that's right; I just did maths with the spaceship operator! :-)

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: How to find the last date of the previous month?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2015-07-08 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls