Ask Your Question
2

How can dates in a single column be compared in SQL Server?

asked 2021-10-14 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-10-19 10:00:00 +0000

nofretete gravatar image

Dates in a single column can be compared in SQL Server by using comparison operators such as greater than (>), less than (<), greater than or equal to (>=) and less than or equal to (<=). You can use the following syntax:

SELECT * FROM tablename WHERE datecolumn > '2021-01-01' AND date_column < '2021-01-31'

This query will select all the rows from the table where the date_column is greater than '2021-01-01' and less than '2021-01-31'. You can also use the BETWEEN operator to select rows within a range of dates:

SELECT * FROM tablename WHERE datecolumn BETWEEN '2021-01-01' AND '2021-01-31'

This query will select all the rows from the table where the date_column is between '2021-01-01' and '2021-01-31'.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-10-14 11:00:00 +0000

Seen: 9 times

Last updated: Oct 19 '21