1.獲取上個月第一天及最後一天.
echo date('Y-m-01', strtotime('-1 month'));
echo "<br/>";
echo date('Y-m-t', strtotime('-1 month'));
echo "<br/>";
2.獲取當月第一天及最後一天.
$BeginDate=date('Y-m-01', strtotime(date("Y-m-d")));
echo $BeginDate;
echo "<br/>";
echo date('Y-m-d', strtotime("$BeginDate +1 month -1 day"));
echo "<br/>";
3.獲取當天年份、月份、日及天數.
echo " 本月共有:".date("t")."天";
echo " 當前年份".date('Y');
echo " 當前月份".date('m');
echo " 當前幾號".date('d');
echo "<br/>";
4.使用函數及數組來獲取當月第一天及最後一天,比較實用,出自網友.
function getthemonth($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=getthemonth($today);
echo "當月的第一天: ".$day[0]." 當月的最後一天: ".$day[1];
echo "<br/>";數組