2007年8月26日 星期日

SQL 時間條件判斷

a month
select contid,id,rentedate from contractext where appyorn ='Y' AND (CONVERT(datetime, RENTEDATE, 112) - GETDATE() > 0) and (convert(datetime,rentedate,112)-convert(datetime,getdate(),112)< convert(datetime,'19000202',112)) and (convert(datetime,rentedate,112)-convert(datetime,getdate(),112)> convert(datetime,'19000129',112))

2 weeks
select contid,id,rentedate from contractext where appyorn ='Y' AND (CONVERT(datetime, RENTEDATE, 112) - GETDATE() > 0) and (convert(datetime,rentedate,112)-convert(datetime,getdate(),112)< convert(datetime,'19000117',112)) and (convert(datetime,rentedate,112)-convert(datetime,getdate(),112)> convert(datetime,'19000114',112))

a week
select contid,id,rentedate from contractext where appyorn ='Y' AND (CONVERT(datetime, RENTEDATE, 112) - GETDATE() > 0) and (convert(datetime,rentedate,112)-convert(datetime,getdate(),112)< convert(datetime,'19000110',112)) and (convert(datetime,rentedate,112)-convert(datetime,getdate(),112)> convert(datetime,'19000107',112))

select convert(datetime,'20070928',112)-convert(datetime,'20070827',112)

select convert(datetime,'20070827',112)

select convert(datetime,'20070901',112)

沒有留言: