Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Month Dates

by Sidhekin (Priest)
on Mar 01, 2007 at 21:33 UTC ( [id://602786]=note: print w/replies, xml ) Need Help??


in reply to Month Dates

I'm probably missing something, as this looks just too easy ... but have you considered modulus?

Your code with minimal changes:

my $tm = localtime; my $this_month = sprintf("%04d%02d?", $tm->year+1900, $tm->mon()+1, ); my $last_month = sprintf("%04d%02d?", $tm->year+1900-($tm->mon()<1 ? 1 : 0), ($tm->mon()-1)%12+1, ); my $last_month_1 = sprintf("%04d%02d?", $tm->year+1900-($tm->mon()<2 ? 1 : 0), ($tm->mon()-2)%12+1, ); my $last_month_2 = sprintf("%04d%02d?", $tm->year+1900-($tm->mon()<3 ? 1 : 0), ($tm->mon()-3)%12+1, );

Edit: Bah, yeah, that was too easy. Forgot the year. Fixed now.

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-18 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found