<?php
function strMonthDate($month, $sourceDate = '', $type = '')
{
if (!$sourceDate) {
$sourceDate = date('Y-m-d H:i:s');
}
$timestamp = strtotime($sourceDate);
$sourceDay = date('d', $timestamp);
$monthFirstDay = date('Y-m-01 H:i:s', $timestamp);
$newDate = strtotime($month . ' month', strtotime($monthFirstDay));
$newMonthDays = date('t', $newDate);
if ($sourceDay > $newMonthDays) {
$sourceDay = $newMonthDays;
}
if ($type == 'date') {
return date('Y-m-' . $sourceDay, $newDate);
} else {
return date('Y-m-' . $sourceDay . ' H:i:s', $newDate);
}
}
$a = strMonthDate(1,'2029-12-31 23:59:59');
var_dump($a);