##查询30天以内的数据 SELECT *,(TO_DAYS(NOW()) - TO_DAYS(create_time) ) AS d FROM `days_user` WHERE TO_DAYS(NOW()) - TO_DAYS(create_time) <= 30; ##方法2 SELECT *,DATE_SUB(CURDATE(), INTERVAL 30 DAY),DATE(create_time) FROM days_user WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= DATE(create_time); ##方法3 比较是否在同一个月份中 SELECT *,DATE_FORMAT( create_time, '%Y%m' ),DATE_FORMAT( CURDATE( ) , '%Y%m' ) FROM days_user WHERE DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )