[已解决]如何在SQL Server中检查日期 [英] [Solved] How to check a date in sql server
本文介绍了[已解决]如何在SQL Server中检查日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个表,其中的字段作为startdate作为datetime,作为endate作为datetime,并且具有记录.现在我的问题是我必须检查输入日期是否在startdate和endate之间.等于开始日期或结束日期.
数据就像
员工姓名,开始日期,结束
Hi All,
I have a table having fields as startdate as datetime and endate as datetime and has records . Now my problem is that I have to check that an input date lies between startdate and endate. and that is equal to startdate or endate.
data is like
Employee name , startdate , endate
rehan ahmad 2011-02-02 00:00:00.000 2011-02-03 00:00:00.000
Mohd Wasif 2011-01-28 00:00:00.000 2011-01-28 00:00:00.000
Mohd Wasif 2011-03-09 00:00:00.000 2011-03-09 00:00:00.000
Mohd Wasif 2011-05-02 00:00:00.000 2011-05-02 00:00:00.000
rehan ahmad 2011-02-23 00:00:00.000 2011-02-26 00:00:00.000
rehan ahmad 2011-03-04 00:00:00.000 2011-03-05 00:00:00.000
rehan ahmad 2011-03-07 00:00:00.000 2011-03-08 00:00:00.000
Mohd Wasif 2011-03-07 00:00:00.000 2011-03-08 00:00:00.000
Mohd Wasif 2011-03-04 00:00:00.000 2011-03-04 00:00:00.000
Mohd Wasif 2011-02-04 00:00:00.000 2011-02-04 00:00:00.000
请让我知道如何获取数据.
在此先感谢
穆罕默德·瓦西夫
更新:
OP发布了已解决的评论.
Please let me know how to fetch data.
thanks in advance
muhammad Wasif
UPDATE:
OP posted a comment that it was solved.
推荐答案
select * from your_table where '01/13/2011' between startdate and enddate
OR
select * from your_table where '01/13/2011' between CONVERT(VARCHAR(10), startdate, 101) AND CONVERT(VARCHAR(10), enddate, 101)
这应该做到-
This should do it -
select * from mytable where startdate <= @myDate and enddate >= @mydate
这篇关于[已解决]如何在SQL Server中检查日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文