浏览文章
文章信息
Mysql数据库查询今天数据(今日数据),查询时间段数据
13214
查询当天数据select * from tab where FROM_UNIXTIME(fabutime, '%Y%m%d') = 20121217;mysql TO_DAYS(date) 函数TO_DAYS(date)给定一个日期date, 返回一个天数 (从年份0开始的天数 )。mysql> SELECT TO_DAYS(950501);-> 728779今天select * from 表名 where to_days(时间字段名) = to_days(now());昨天SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) - TO_DAYS( 时间字段名) <= 17天SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名)近30天SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名)本月SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )上一月SELECT * FROM 表名 WHERE PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( 时间字段名, '%Y%m' ) ) =1#查询本季度数据select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(now());#查询上季度数据select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(DATE_SUB(now(),interval 1 QUARTER));#查询本年数据select * from `ht_invoice_information` where YEAR(create_date)=YEAR(NOW());#查询上年数据select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval 1 year));
转载地址:http://blog.csdn.net/mayunyun1987100/article/details/38664931