Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 convert nvarchar to datetime

Author  Topic 

inbs
Aged Yak Warrior

860 Posts

Posted - 2012-09-03 : 04:06:33
how to convert nvarchar to date time?

i try to convert for example this valur in my table :
02/09/2012 20:30:01

but i get this error:
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-09-03 : 04:26:48
you must have invalid data in the column.

use isdate() to verify


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-09-03 : 10:16:24
quote:
Originally posted by inbs

how to convert nvarchar to date time?

i try to convert for example this valur in my table :
02/09/2012 20:30:01

but i get this error:
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.


Show us the code you used

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-03 : 15:26:53
quote:
Originally posted by inbs

how to convert nvarchar to date time?

i try to convert for example this valur in my table :
02/09/2012 20:30:01

but i get this error:
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.


is all date values in same format? if possible pass all of them in consistent format and try if format can be unambiguos like yyyymmdd

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-03 : 15:35:32
see this too

http://visakhm.blogspot.com/2011/12/why-iso-format-is-recommended-while.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -