mysql 时间戳查询 当天 本周 当月 数据

from_unixtime(time_stamp)   ->  将时间戳转换为日期

 

          unix_timestamp(date)             ->  将指定的日期或者日期字符串转换为时间戳

 

 date('Y-m-d', time());   //当天

 date('Y-m-d', strtotime('last day this week'));//本周
 date('Y-m-01', time());//本月
 date('Y-m-d H:i:s', time());//结束时间


SELECT COUNT(1) FROM table WHERE `time` >= UNIX_TIMESTAMP( "'. date('Y-m-d', time()).'" ) AND `time` <= UNIX_TIMESTAMP( "'.date('Y-m-d H:i:s', time()).'" );
SELECT COUNT(1) FROM table WHERE `time` >= UNIX_TIMESTAMP( "'.date('Y-m-d', strtotime('last day this week')).'" ) AND `time` <= UNIX_TIMESTAMP( "'.date('Y-m-d H:i:s', time()).'" );
SELECT COUNT(1) FROM table WHERE `time` >= UNIX_TIMESTAMP( "'. date('Y-m-01', time()).'" ) AND `time` <= UNIX_TIMESTAMP( "'.date('Y-m-d H:i:s', time()).'" );

你可能感兴趣的:(mysql)