如何使用SQL查询检查日期范围是否在给定日期 [英] how to check the date range falls in the given dates using sql queries

查看:77
本文介绍了如何使用SQL查询检查日期范围是否在给定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





im创建一条记录,其开始日期为1-1-2013​​,结束日期为3-2-2013 ,我有另一个保存的记录,开始日期为''21-1-2013'',结束日期为''31-1-2013''我想比较两个记录日期与SQL查询如何做到这一点? br $>


谢谢



i m creating a record with start date as ''1-1-2013'' and end date as ''3-2-2013'', and i have another saved record with start date as ''21-1-2013'' and end date as ''31-1-2013'' i want to compare both records dates with sql queries how to do it ?.

Thanks

推荐答案

Hello nrkhi401,



我没有得到你的查询,但我理解的是:

你想写的查询只有在给定时才会返回结果,并且结束日期介于''1-1-之间2013''和''3-2-2013''



以下为此解决方案假设考虑



Hello nrkhi401 ,

I didn''t got your query but what I understood is like :
"You want to write query which will return result only when given from and end date falls between ''1-1-2013'' and ''3-2-2013''"

and for this below is the solution suppose consider

CREATE PROCEDURE(@FrmDate DATE , @EndDate DATE)
 BEGIN
  SELECT * FROM tbl WHERE
  tblStDate BETWEEN @FrmDate AND @EndDate
  AND
  tblEdDate BETWEEN @FrmDate AND @EndDate
  AND
  @FrmDate BETWEEN tblStDate AND tblEdDate
  AND
  @EndDate BETWEEN tblStDate AND tblEdDate
 END





希望这有帮助

--RDBurmon



Hope this helps
--RDBurmon


0)使用ISO 8601格式(YYYY-MM-DD)

1)不要存储为文本,存储为DATE或DATETIME

2)看看BETWEEN



3)你是什么试图找出这两个记录?
0) Use an ISO 8601 format (YYYY-MM-DD)
1) Don''t store as text, store as DATE or DATETIME
2) Look into BETWEEN

3) What are you trying to find out about these two records?


这篇关于如何使用SQL查询检查日期范围是否在给定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆