php常见小技巧,分割时间,直接上代码。
if (!empty($post['date'])) {
// - 分割时间段
$date = explode(",", $post['date']);
$start = $date[0];
$end = $date[1];
$param['start'] = $start;
$param['end'] = $end;
if (empty($sql)) {
$sql .= " create_time between '$start' and '$end'";
} else {
$sql .= " and create_time between '$start' and '$end'";
}
}
//获取当天开始到结束
$time = date('Y-m-d');
$start = date('Y-m-d').' 00:00:00';
$end = date('Y-m-d h:i:s',strtotime($time)+86399);
select from_unixtime(1464969600); //2019-06-0400:00:00;
select str_to_date('2019-06-04', '%Y-%m-%d %H'); //'2019-06-0400:00:00;
MySQL日期格式化(format)取值范围。