T-SQL reference › date vs datetime

date vs datetime vs datetime2 in SQL Server

A birthday is a date. An order stamped at 09:14 is a datetime (or datetime2). Mixing them is how “yesterday” leaks today.

Pick one

SELECT CAST(GETDATE() AS date) AS just_day,
       GETDATE() AS datetime_now,
       SYSDATETIME() AS datetime2_now;

How to filter a timestamp by a day is on datetime to date.

Try it on Harbour & Co

James Rowe (Sales Manager) needs this now: “Need last week’s orders over £50 for the 10am. Don’t include today. Newest first.” Write the query, run it, send the results. Free.

Take the ticket →

Learn it on a real ticket

Monday is free on WorkSQL. A colleague’s ticket lands, you write the T-SQL, we mark it. No videos. Five minutes.

Clock in free See Monday’s tickets