date('Y-m-d',156468789)
;将时间戳转换为年月日形式
shrtotime("20200902")
;将具体日期转换成时间戳
date(‘Y-m-d’);获取当前日期
如果传过来是2020-09这样的,需要返回这一个月的数据的话
$date = '2020-09';
$time = strtotime(!empty($date) ? $date : 0);
$month_start = date('Y-m-d', $time);
$mdays = date('t', $time);
$month_end = date('Y-m-' . $mdays, $time);
查询当天:
$start = strtotime(date('Y-m-d'));;
$end = strtotime(date('Y-m-d H:i:s'));//
SELECT * FROM `table_name` WHERE `time` >= {$start} AND `time` <= {$end}
查询本周:
SELECT weekday( 'Y-m-d 00:00:00' )
SELECT weekday( ''Y-m-d H:i:s )
查询本月:
$start = date('Y-m-01 00:00:00');
$end = date('Y-m-d H:i:s');
SELECT * FROM `table_name` WHERE `time` >= unix_timestamp('”.$start.”') AND `time` <= unix_timestamp('$end')
查询本年:
$start = date('Y-01-01 00:00:00');
$end = date('Y-m-d H:i:s');
SELECT * FROM `table_name` WHERE `time` >= unix_timestamp( '$start' ) AND `time` <= unix_timestamp( '$end' )