Yesterday I ran into an issue with PHP’s strtotime not properly adding a month. On ‘2011-05-31’ I ran:
date('Y-m-d',strtotime( '+1 month', strtotime('now')));
Which returns ‘2011-07-01’ when I am expecting ‘2011-06-30’.
MySQL doesn’t have any issue doing this.
I’d rather not reinvent the wheel with this, as it is fairly easy to make mistakes with date calculations from my experience.
Does anyone have a reliable and tested solution for this for PHP 5.1?
It certainly is possible in PHP: Check the strtotime manual, especially this comment.
If you have a MySQL connection available,
SELECT DATE_ADD( '2011-05-31', INTERVAL 1 MONTH )would be less redundant since the (correct) functionality is already implemented without you having to implement it yourself.