<?php
// PHP: date functions' results related to the NEXT month are not correct
// http://stackoverflow.com/questions/10834350/php-date-functions-results-related-to-the-next-month-are-not-correct-php-bugs
// testing function for printing out variables
function my_var_export($stuff, $text = '...'){
return '<p>'.$text.':</p><pre>'.var_export($stuff, TRUE).'</pre>';
}
// Current date as a MySQL-compatible timestamp
$current_date_timestamp = date('Y-m-d H:i:s');
// Get next month as a timestamp
$next_month_timestamp = date('Y-m-d H:i:s', strtotime('next month'));
// Get last day of the current month/Get number of days in the current month
$last_day_current_month = date('t', strtotime('today'));
// Get last day of the next month/Get number of days in the next month
$last_day_next_month = date('t', strtotime('next month'));
$dateObj = new DateTime();
// Period 1 month --> http://www.php.net/manual/en/dateinterval.construct.php
$dateInterval = 'P1M';
$dateObj->add(new DateInterval($dateInterval));
$dateTime_next_month_timestamp = $dateObj->format('Y-m-d H:i:s');
echo my_var_export(strtotime('today'), "strtotime('today');");
echo my_var_export(strtotime('next month'), "strtotime('next month');");
echo my_var_export($current_date_timestamp, "Current date as a MySQL-compatible timestamp [ date('Y-m-d H:i:s'); ]");
echo my_var_export($next_month_timestamp, "Get next month as a timestamp [ date('Y-m-d H:i:s', strtotime('next month')); ]");
echo my_var_export($dateTime_next_month_timestamp, "Get last day of the next month as a timestamp with DateTime class [ \$dateObj->add(new DateInterval('P1M')); \$dateObj->format('Y-m-d H:i:s'); ]");
echo my_var_export($last_day_current_month, "Get last day of the current month/Get number of days in the current month [ date('t', strtotime('today')); ]");
echo my_var_export($last_day_next_month, "Get last day of the next month/Get number of days in the next month [ date('t', strtotime('next month')); ]");
die();