Question : SQL Server problem with date format

Hi.

My database is managed by a British hosting company and my site is British. problem is the SQL Server database seems to be holding dates in the default US format, ie mdy.

This is causing problem when I run queries against date columns. So a date held as 2/17/2010 should be less than today's date ( 17th Feb 2010 ), but this is failing in my select statement. Eg.

select ad_expiry_date < getdate()

Iv'e tried using SET DATEFORMAT dmy in my stored procedure but doesn't help.

Any ideas please?

Thanks.

Answer : SQL Server problem with date format

I confirm that the SET DATEFORMAT will indeed change the behavior, though I got with your code at least 1 row back (the <= getdate()).
playing around with dateformat made some differences, but the solution, to return expected results, was to indeed replace:

GETDATE()
by
CAST(GETDATE() AS SMALLDATETIME)

and you get results in any settings.

Random Solutions  
 
programming4us programming4us