[thelist] Using Wildcards and Dates in SQL Server

Ken Kogler ken.kogler at curf.edu
Tue Jun 17 12:15:33 CDT 2003


> So you're trying to get all records for June 2003? Try this:
> 
> SELECT * from curEvents where DATEPART(month, GETDATE()) = 6 and
> DATEPART(year, GETDATE()) = 2003

Doesn't work -- this returned all dates in the table.

The dates are stored in a single column called "eDate" in the
'mm/dd/yyyy' format. I thought about doing something like "select where
left(eDate,2) = 6" but I can't always guarantee that the month is two
digits. SQL Server stores January 1st as 1/1/2003 instead of 01/01/2003,
and I don't think there's any way in SQL to catch both cases.

--ken



More information about the thelist mailing list