- var_dump: documentation ( source)
- mktime: documentation ( source)
- date: documentation ( source)
<?php
$foo = '2011-1-31 00:00:00';
$date = new DateTime($foo);
$date->modify('1 month');
var_dump($date);
$new_month = $date->format('m');
$new_day = $date->format('d');
$new_year = $date->format('Y');
$last_month_timestamp = mktime(0, 0, 0, $new_month, $new_day, $new_year);
$num_days_last_month = date('t', $last_month_timestamp);
$days_offset = $num_days_last_month - $new_day;
$date = $date->modify('' . $days_offset . ' days');
var_dump($date);