I need to convert varchar to datetime..I've tried something like following
declare @date varchar(150)='01/10/15'
declare @datenew date
select @datenew=convert(smalldatetime,CONVERT(nvarchar(10), CAST(@date AS DATETIME), 101) ,101)
print @datenew
the output is : 2015-01-10
But when I change the date to
declare @date varchar(150)='13/10/15'
it throws the following error.. :
"The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."
the resultant format of datetime is YYYY-MM-DD. I want the result in the format DD-MM-YYYY..
What do i do..
Thanks in advance
Varchar to datetime conversion in sql 2008
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Shubham KumarRank #621 · 3.8K reputationPosted Feb 2, 2016, 1:26 AM EST
Avinash AherRank #5,790 · 286 reputationPosted Feb 2, 2016, 1:32 AM EST