查詢出當(dāng)天數(shù)據(jù):
SELECT * FROM `table` WHERE date(時間字段) = curdate();
查詢出當(dāng)月字段:
SELECT *
FROM `table`
WHERE month( 時間字段) = month( now( ) ) ;
時間格式為1219876…… UNIX時間,只要應(yīng)用“FROM_UNIXTIME( )”函數(shù)
例如查詢當(dāng)月:
SELECT *
FROM `table`
WHERE month( from_unixtime( reg_time ) ) = month( now( ) ) ;
查詢上一個月的呢?變通一下!
SELECT *
FROM `table`
WHERE month( from_unixtime( reg_time ) ) = month( now( ) ) -1;