sql server實(shí)現(xiàn)
日期部分 縮寫(xiě) year yy, yyyy quarter qq, q month mm, m dayofyear dy, y day dd, d week wk, ww weekday dw hour hh minute mi, n second ss, s millisecond ms
/**//*計(jì)算今天是星期幾*/
select datename(weekday,getdate())
/**//*查詢本年的數(shù)據(jù)*/
select * from users where year(time)=year(getdate())
/**//*查詢本月的數(shù)據(jù),time是表users中代表時(shí)間的字段*/
select * from users where month(time)=month(getdate()) and year(time)=year(getdate())
/**//*查詢今天的數(shù)據(jù),time 是表中代表時(shí)間的字段*/
select * from users where day(time)=day(getdate()) and month(time)=month(getdate()) and year(time)=year(getdate())
/**//*計(jì)算那一天是星期一*/
select dateadd(wk,datediff(wk,0,getdate()),0)
/**//*計(jì)算那一天是周末*/
select dateadd(wk,datediff(wk,0,getdate()),6)
/**//*查詢本周的數(shù)據(jù)*/
select * from users where datepart(wk, time)=datepart(wk,getdate()) and datepart(yy, time)=datepart(yy,getdate())
/**//*查詢本日的記錄*/
select * from users where(datediff(dd, time,getdate())=0)
/**//*查詢本月的記錄*/
select