in reply to Re: Datetime Problem - Wrong Time
in thread Datetime Problem - Wrong Time

Oh it subtracts twice!!! I just literally facepalmed.... Updated to:

#!/usr/bin/perl use DateTime; $dt = DateTime->now->subtract(months => 1); $month = $dt->strftime("%m"); $year = $dt->year(); print $dt."\n"; print $month."\n"; print $year."\n";

Works now! Thanks monks :D

Replies are listed 'Best First'.
Re^3: Datetime Problem - Wrong Time
by tobyink (Canon) on Feb 07, 2012 at 23:03 UTC

    FYI, if you want to use DateTime the way you were using it, there's clone:

    #!/usr/bin/perl use DateTime; $dt = DateTime->now(); $month = $dt->clone->subtract(months => 1)->strftime("%m"); $year = $dt->clone->subtract(months => 1)->year(); print $dt."\n"; print $month."\n"; print $year."\n";