PHP获取上个月第一天及最后一天
$firstday = date('Y-m-01', strtotime('-1 month'));
$lastday = date('Y-m-t', strtotime('-1 month'));
PHP获取当月第一天及最后一天
$firstday = date('Y-m-01', strtotime(date("Y-m-d")));
$lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
PHP获取当前年份、月份、日及当月天数
echo "当前年份:".date('Y')."年<br/>";
echo "当前月份:".date('m')."月<br/>";
echo "本月共有:".date("t")."天<br/>";
echo "今日为:".date('d')."号</br>";
示例:在函数中获取当月第一天及最后一天
function getdays($date)
{
$firstday = date('Y-m-01', strtotime($date));
$lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
return array($firstday,$lastday);
}
$today = date("Y-m-d");//获取当天作为参数
$day=getdays($today);
echo "当月的第一天: ".$day[0]."<br/>当月的最后一天: ".$day[1];