Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Adding to dates

by explorer (Chaplain)
on Aug 23, 2006 at 02:29 UTC ( [id://569008]=note: print w/replies, xml ) Need Help??


in reply to Adding to dates

And this is a DateTime solution:

#!/usr/bin/perl -l use DateTime; use DateTime::Duration; my $date = DateTime->new( year => 2006, month => 12, day => 31, locale => 'en_US', ); my $duration = DateTime::Duration->new( months => 1, end_of_month => 'preserve', ); for ( 1..12 ) { $date->add( $duration ); # One month more print $date->mdy('/'); # And show it }
Updated: With Ponky advice, rest:
use DateTime; my $date = DateTime->last_day_of_month( year => 2006, month => 12 ); print $date->add( months => 1, end_of_month => 'preserve' )->mdy('/') +foreach 1..12;

Replies are listed 'Best First'.
Re^2: Adding to dates
by Ponky (Curate) on Aug 23, 2006 at 02:38 UTC
    A little improvement is to include the duration definition in the add call:
    $date->add( months => 1, end_of_month => 'preserve' );
    Then you don't need the use DateTime::Duration either.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-20 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found