sql查詢某段時間內的數據


查詢半小時內數據的方法

1、select * from 表名 where datediff(minute,createtime,getdate())<30

2、select * from 表名 where createtime>=DateAdd(minute,-30,GETDATE()) and createtime<getdate()
查詢當天數據的方法

1、select * from 表名 where datediff(day,createtime,getdate())=0

2、select * from 表名 where convert(varchar(8),createtime,112)=convert(varchar(8),GETDATE(),112) 推薦此種,效率較高

3、select * from 表名 where CAST(CreateDate as date)=CAST(GETDATE() as date)

3、string.Format("select * from 表名 where CreateDate>='{1} 0:00:00' AND CreateDate<='{1} 23:59:59'",DateTime.Now.ToString("yyyy-MM-dd"))

查詢當天生日的方法(每年當天都需要)

1、select * from 表名 where MONTH(Birthday)=MONTH(GETDATE()) and DAY(Birthday)=DAY(GETDATE())


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM