in reply to get previous month in two digit number

Or roll-out your own if you want, using localtime like so:
A

my $present_month = ( localtime() )[4] + 1; print sprintf "current month: %d\nprevious month: %d\n", $present_mont +h, $present_month - 1;
A: UPDATE:
Obviously, this breaks when the current month is January, because the previous month will then be "0", which doesn't translate to month "12" as we wanted.
Please, use the tested module like Time::Piece and others as Loops and others had mentioned.
'Am sorry I missed that big time...
Loops++ for catching that.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Replies are listed 'Best First'.
Re^2: get previous month in two digit number
by Loops (Curate) on Jul 19, 2013 at 04:24 UTC

    Rolling your own is often not the right answer though. It means that there are many implementations to update when things change. And unfortunately, the above code breaks when the current month is January, October, November or December.

Re^2: get previous month in two digit number
by flexvault (Monsignor) on Jul 20, 2013 at 07:34 UTC

    2teez,

    Don't be so hard on yourself. A simple test improves the script.

    $present_month - 1; if ( $present_month == 0 ) { $present_month = 12; }

    Now, if the OP needs other features of the referenced modules, then that's great, but if all he needs is your script, that's great also.

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin

Re^2: get previous month in two digit number
by hdb (Monsignor) on Jul 19, 2013 at 13:52 UTC

    Just do

    ( $present_month - 1 || 12 )

    to implement rollover from January into December.