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

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'

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2016-10-24 10:37 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (304 votes). Check out past polls.