on-internet
← Community

Compare dates in T-SQL

Stack Overflow ·

I have a table with a column date of datatype varchar. The values are '2022-03-08 07:00',2022-03-08 07:30 ... . In my stored procedure I have a parameter of type DATE and with a value '2022-3-8' DECLARE @d DATE = '2022-3-8' SELECT *, r.date AS date, @d AS d FROM Readings AS r WHERE CONVERT(VARCHAR, r.date, 23) = @d How can I compare these two? I get this error: Conversion failed when converting date and/or time from character string. I would like to remove time component and compare '2022-03-08' vs '2022-3-8'. Notice leading zero in month and day numbers.

Comments

Sign in or sign up to comment and upvote.

No comments yet.