I need to convert a nvarchar
value to datetime
in T-SQL. The value is in ddmmyyyy
format, e.g. 23072009
I need to convert to datetime
in T-SQL.
I tried
select convert(datetime, '23072009', 103)
But it is throwing error.
"The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value."
Any idea
Thanks
Rebuild your format to yyyymmdd
.
declare @D varchar(8)
set @D = '23072009'
select cast(right(@D, 4)+substring(@D, 3, 2)+left(@D, 2) as datetime)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With