in reply to Datetime Problem - Wrong Time

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

Replies are listed 'Best First'.
Re^2: Datetime Problem - Wrong Time
by solarisfire (Novice) on Feb 07, 2012 at 15:10 UTC

    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

      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";