in reply to Changing dates

Coding it yourself is nearly always the wrong way to handle date math. Check out Date::Calc and the DateTime modules

If you really must do this yourself, read through this recent node: Increment through date range by day with only standard modules. for ideas on how to do this correctly.