sql 时间比较 查询语句

1 查询时间段:

则直接字段 大于 或小于该时间段 即可
select * from t_person where born >= '2000-01-01' and  born <= '2017-01-01' 
或者用 BETWEEN  AND (前开后闭)

2 查询某天、某周、某月、某年 的数据

select * from t_person where  DATEDIFF(day, "2017-01-01", '2017-01-01')   ;

select * from t_person where  DATEDIFF(week, "2017-01-01", '2017-01-01')   ;

select * from t_person where  DATEDIFF(month, "2017-01-01", '2017-01-01')   ;

select * from t_person where  DATEDIFF(year, "2017-01-01", '2017-01-01')   ;



猜你喜欢

转载自blog.csdn.net/phn555/article/details/77934763
今日推荐