in reply to How to get the correct incremented month through DateTime::Precise ?

#/usr/bin/perl use strict; use warnings; use Time::Piece; use Time::Piece::Month; use Time::Seconds; my $date = Time::Piece->strptime( "2002-01-31", '%Y-%m-%d' ); $date += ONE_MONTH; print "\n Date:",$date->ymd;
  • Comment on Re: How to get the correct incremented month through DateTime::Precise ?
  • Download Code

Replies are listed 'Best First'.
Re^2: How to get the correct incremented month through DateTime::Precise ?
by davorg (Chancellor) on Oct 16, 2006 at 11:43 UTC

    That's a rather strange approach to take. Time::Seconds defines one month as 2,629,744 seconds (exactly one twelfth of a year). So by adding one month, you're actually adding 30 days, 10 hours, 29 minutes and 4 seconds. Which seems a strange way to approach this problem.

    This issue becomes obvious if you print out the time parts of your object too.

    #/usr/bin/perl use strict; use warnings; use Time::Piece; use Time::Seconds; my $date = Time::Piece->strptime( "2002-01-31", '%Y-%m-%d' ); print "\n Date:",$date->ymd, ' ', $date->hms; $date += ONE_MONTH; print "\n Date:",$date->ymd, ' ', $date->hms;

    Which displays:

    Date:2002-01-31 00:00:00 Date:2002-03-02 10:29:04
    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg