0
点赞
收藏
分享

微信扫一扫

mysql中的查询本日、本周和本月的SQL语句


首先确定当前时间

如果在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;






举报

相关推荐

0 条评论