SQL Interview: 62 Selecting rows for a date

This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database.
Section: Development Level: Intro
Question:
You have a table of transactions. You need to select all the transactions for a particular date, based on the TransactionDateTime column. It holds datetime data type value. The date is stored in the @RequiredDate variable.
How can you create the WHERE clause that is needed?
Answer:
You need to exclude the time value. There are several ways to do this:
WHERE CAST(TransactionDateTime AS date) = @RequiredDate
WHERE CONVERT(date, TransactionDateTime) = @RequiredDate
WHERE TransactionDateTime >= @RequiredDate
AND TransactionDateTime < DATEADD(day, 1, @RequiredDate)
2025-07-11