[thelist] Using Wildcards and Dates in SQL Server

rudy r937 at interlog.com
Tue Jun 17 17:10:22 CDT 2003

> 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.

actually, this is a very common misperception

datetime values are not stored in sql server as date strings, they are
stored as integers which represent the number of days since some base date
(january 1 1753, i believe)

whenever you display a date, sql server automatically converts it for you,
using default formatting

you can select a different format with the CONVERT function --

> Is there a reason why DatePart() is preferable to Month() or Year()?

not really

MONTH() and YEAR() are semantically more obvious

More information about the thelist mailing list