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
 General SQL Server Forums
 New to SQL Server Programming
 string to date conversion

Author  Topic 

dsscholar
Starting Member

6 Posts

Posted - 2011-09-20 : 04:51:06

I have a nvarchar column with format like '30 jul 2011 11:30'. I want this to be converted to date column in the format '30 jul 2011'. Please help with the syntax.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-20 : 05:43:22
you shouldnt be worried at format in which dates are stored in table. so far as field is datetime you can apply format functions available in front end languages to get it to format you want or even use convert.
now for converting from nvarchar to date you can use CONVERT() function like

convert(datetime,field,113)

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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-09-23 : 06:12:50
Also make sure to validate the date with isdate() and len() functions
http://beyondrelational.com/blogs/madhivanan/archive/2007/09/24/handle-isdate-with-care.aspx

Madhivanan

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

- Advertisement -