1. 程式人生 > >sql 時間比較 查詢語句

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')   ;