Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Last month's number with Time::Piece

by Anonymous Monk
on Dec 04, 2014 at 19:04 UTC ( [id://1109277]=note: print w/replies, xml ) Need Help??


in reply to Re: Last month's number with Time::Piece
in thread Last month's number with Time::Piece

To complement, with this I am trying to also get the last day of the last month, here is what I am using, it might be a shorter way as well:
use warnings; use strict; use Time::Piece; my $t = Time::Piece->new(); my $year = $t->year; my $last_month = $t->add_months(-1)->mon; # Pass the last month and year to a new Time::Piece object my $t_last_month = Time::Piece->strptime("$last_month$year", "%m%Y"); # Now use Time::Piece month_last_day to get it my $last_day_of_month = $t_last_month->month_last_day; print "Last Month = $last_month - It's last day = $last_day_of_month \ +n";

Thanks!

Replies are listed 'Best First'.
Re^3: Last month's number with Time::Piece
by Anonymous Monk on Dec 05, 2014 at 14:20 UTC
    just a short observation - to make this work correctly, add a line like this before calling strptime: if (length($last_month) == 1) { $last_month = "0" . $last_month; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-24 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found