Click here to Skip to main content
15,913,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can anyone tell me why the error occurs when executing:
SQL
SELECT  CONVERT(Datetime,dob,102)
FROM    Table1

Here dob is Varchar(10)
Date is in dd/mm/yyyy(5/24/1995) format

Thanks in advance...
Posted
Updated 31-Jan-11 4:19am
v5
Comments
Manas Bhardwaj 31-Jan-11 10:20am    
whts the error?

Date is in dd/mm/yyyy(5/24/1995) format


5/24/1995 is m/d/yyyy format.

Following works fine
SQL
SELECT CONVERT(datetime, '5/24/1995', 102) AS Expr1

and
SQL
SELECT CONVERT(datetime, dob, 102) from testTable


Make sure you have proper data in all rows. What error you get exactly?
 
Share this answer
 
Without seeing your data, it is difficult to be sure, but I would assume that the "dob" field does not contain date information in the correct format: i.e. "yyyy.MM.dd" as specified by the "102" style parameter
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900