首先确定当前时间
如果在PHP中,则当前时间为
$time = time();如果在mysql中,则当前时间为
now()本日查询示例如下:
select * from order where DATEDIFF(from_unixtime(add_time),now())=0 '
$time = time();
$weekfirst = strtotime('-1 week Monday');SQL如下:
select * from order where ".$weekfirst." <= add_time <= ".$time
$time = time();
$monthfirst = mktime(0,0,0,date('m'),01,date('Y'));SQL如下:
select * from order where ".$monthfirst." <= add_time <= ".$time;
本文介绍了如何在PHP和MySQL中获取当前时间,并展示了如何利用这些时间信息进行本日、本周及本月的数据查询。通过具体SQL示例,读者可以学会如何高效地筛选所需时间段内的数据。
360

被折叠的 条评论
为什么被折叠?



