AddyProg
AddyProg

Reputation: 3050

Comparing String DateTime in SQL Server 2008

I have DateTime value stored in a VARCHAR type column in a database and now I want to compare dates in select query but it's giving me an error. The value stored in the column looks like this 17/3/14 03:07:03

Here is what I have tried

select * 
from [User]
WHERE myDate > convert(datetime, '31-5-2012')

Upvotes: 1

Views: 248

Answers (1)

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28413

Try this

SET DateFormat DMY

SELECT * FROM [User]
WHERE myDate > CAST('31-5-2012' AS DATETIME)

Upvotes: 2

Related Questions