如何在两个日期之间找到日期 [英] How to find Date between two dates

查看:87
本文介绍了如何在两个日期之间找到日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL表,其中包含每周的开始和结束日期。我想要检查今天的日期是在表中的两个日期之间。我怎样才能在SQL中实现这一点

i have a SQL table with start and end dates of every week. i jus want to check todays date is between which two dates in the table. how can i achieve this in SQL

推荐答案

SELECT  CASE WHEN (GETDATE() BETWEEN DateA AND DateB) THEN
CAST(1 as bit) ELSE CAST(0 as bit) END AS isCurrentWeek
FROM TableName


尝试:

Try:
SELECT * FROM MyTable WHERE GETDATE() BETWEEN startOfWeekColumn AND endOfWeekColumn


怎么样?br / >
What about
...
WHERE today_date BETWEEN week_start AND week_end





现在这些是您需要的三个值使用; today_date是您要检查的日期,而week_start和week_end是日期的值或您要在中检查的范围。它们可以是列,参数或其他硬编码值。它们取决于您的使用方式。无论如何,整体通用的解决方案是你需要使用 WHERE [ ^ ]子句和 BETWEEN和AND [ ^ ]运算符检查变量是否在此范围内



Now these are three values that you require to use; today_date is the date that you want to check, and week_start and week_end are values for the dates or the range you want to check within. They can be columns, parameters or other hard-coded values. They depend on how you want to use. Anyways, the overall general solution is that you need to use WHERE[^] clause and BETWEEN and AND[^] operators to check whether a variable is within this range.


这篇关于如何在两个日期之间找到日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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