Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

SQL
SELECT  CASE WHEN (GETDATE() BETWEEN DateA AND DateB) THEN
CAST(1 as bit) ELSE CAST(0 as bit) END AS isCurrentWeek
FROM TableName
 
Share this answer
 
v3
Try:
SQL
SELECT * FROM MyTable WHERE GETDATE() BETWEEN startOfWeekColumn AND endOfWeekColumn
 
Share this answer
 
What about
SQL
...
WHERE today_date BETWEEN week_start AND week_end


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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900