I have a strange problem that I have never encountered with PHP before when using their strtotime() function.
$original = strtotime('2015-12-31 12:34:56');
$time = strtotime('+ 2 month', $original);
echo date('m/d/y H:i:s', $original),'<br>',date('m/d/y H:i:s', $time);
What I expect to get as output:
12/31/15 12:34:56
02/29/16 12:34:56
What I actually get as output:
12/31/15 12:34:56
03/02/16 12:34:56
How can I account for this calculation error? After quite a bit of investigation I realize that PHP uses an average of 30.5 days to do calculations like this. I don't really care so much about the "WHY" this happens, but rather what I can do to account for it. I have some ideas in mind that involve writing a wrapper for strtotime() when involving month calculations, but it seems like a convoluted approach...
There is an existing answer for this question but the time component is not mentioned in the question (only a date), hence I don't consider this question a duplicate of that one. In addition, I am mainly seeking an improvement to the way we handle such an issue, not necessarily a solution posted for the aforementioned question. If, however, I am wrong to do this then you are welcome to remove this question :(