Monday, January 13, 2025
HomeProgrammingsql server - SQL query to select dates between two dates

sql server – SQL query to select dates between two dates

To select records with dates between two specific dates in SQL Server, use the BETWEEN operator in a WHERE clause:

sql
SELECT *
FROM TableName
WHERE DateColumn BETWEEN 'YYYY-MM-DD' AND 'YYYY-MM-DD';

For inclusive date filtering, both start and end dates are included. Ensure the dates are in a format compatible with SQL Server (YYYY-MM-DD is standard).

See also  How to center a button in CSS

If time values are part of the column, adjust the query to account for the full day range:

sql
WHERE DateColumn >= 'YYYY-MM-DD' AND DateColumn < 'YYYY-MM-DD 23:59:59.999';

Replace TableName and DateColumn with your table and column names.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x