What's the correct SQL Server syntax for filtering dates after a specific date?

I'm stuck on a SQL Server query. I want to get all records from my table where the date is on or after April 1, 2010. Here's what I tried:

SELECT * FROM myTable
WHERE dateColumn >= '2010-04-01'

The dateColumn format is like '2010-03-04 00:00:00.000'.

But it's not working as expected. Am I missing something in the syntax? Maybe there's a special way to compare dates in SQL Server that I don't know about?

Any help would be great. Thanks!

hey there! your query looks good. have u tried the CONVERT function? like:

WHERE dateColumn >= CONVERT(datetime, ‘2010-04-01’)

maybe that helps. also, what is your dateColumn datatype? curious if that affects results.

Your query syntax is correct for SQL Server. However, to ensure accurate date comparisons, it’s advisable to use the ISO 8601 date format. Try modifying your query like this:

SELECT * FROM myTable
WHERE dateColumn >= ‘20100401’

This format eliminates any potential ambiguity with date interpretation. If you’re still encountering issues, verify that dateColumn is indeed a datetime data type. You can check this using:

SELECT DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = ‘myTable’ AND COLUMN_NAME = ‘dateColumn’

If it’s not a datetime type, consider converting it or adjusting your table schema for more reliable date operations.

yo GrowingTree! ur query looks fine tbh. maybe check if dateColumn is actually datetime? if its varchar, try CAST:

WHERE CAST(dateColumn AS datetime) >= ‘2010-04-01’

also double-check ur data, sometimes weird stuff happens. good luck!