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")); //在数据库between查询时 为date('Y-m-d', strtotime("$BeginDate +1 month")); 后面同理
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/>";
本周第一天和最后一天
$weekfir=date('Y-m-d', time()-86400*date('w',time())+(date('w',time())>0?86400:-518400));
$weekend=date('Y-m-d', time()-86400*date('w',time())+(date('w',time())>0?86400:-/*6*86400*/518400)+518400);
下周第一天和最后一天
$nweekfir=date('Y-m-d', strtotime('+1 week last monday'));
$nweekend=date('Y-m-d', strtotime('+1 week last monday')+86400*6);
当用程序查询很慢时可用mysql语句查询出来创建视图表加快速度
MYSQL语句
当天
where unix_timestamp(sick.create_time)>=UNIX_TIMESTAMP(DATE(NOW())) and unix_timestamp(sick.create_time)<(UNIX_TIMESTAMP(DATE(NOW()))+86400)
当天零点
UNIX_TIMESTAMP(DATE(NOW()))