且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在两个日期之间找到日期

更新时间:2023-01-29 19:28:34

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.