I am using
$jsdate = date("Y, m, d", strtotime('-1 month', (strtotime($date))));
to convert my dates from
2011-03-28
to
2011, 02, 28
Problem is this is producing unpredictable results. For example today I got
2011-03-28
converted to
2011, 02, 28 // OK
AND
2011-03-29
to
2011, 03, 01 // not OK!
Does anyone know what's wrong here? I wonder if the calculation is inaccurate because of the -1 month.
Is there a way of simply subtracting 1 from m in ...date("Y, m, d", ...?
MORE INFO:
My data needs to be formatted as JavaScript Date Object in which January is 0, Feb is 1, etc. Therefore there is not a need to specifically subtract 1 month but actually subtract 1 from the month integer. At the end, the resulting string is not supposed to be 1 month earlier, but actually the same date, represented using JS Date Object style. I believe @vprimachenko's answer below is a good solution. I apologize if this wasn't clear in my OP.
Thanks!
1as an integer fromm1frommonth. thanks for pitching in.