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 2005 Forums
 Transact-SQL (2005)
 nvarchar to datetime

Author  Topic 

havejeet
Starting Member

5 Posts

Posted - 2009-03-31 : 02:50:24
Hi all,

I have data like 20070423142807 and now i want to convert it to datetime like 04/23/2007 14:28:07 (i.e. mm/dd/yyyy hh:mm:ss) - please suggest me earliest.


thanks
Jeet

regards

Jeet

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-31 : 03:02:51
declare @n nvarchar(20)
set @n='20070423142807'
select cast(stuff(stuff(stuff(@n,9,0,' '),12,0,':'), 15,0,':') as datetime)


Madhivanan

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

havejeet
Starting Member

5 Posts

Posted - 2009-03-31 : 03:31:04
Genius-Buddy, thanks a bunch!

Jeet

regards

Jeet
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-31 : 03:48:22
quote:
Originally posted by havejeet

Genius-Buddy, thanks a bunch!

Jeet

regards

Jeet


You are welcome

Madhivanan

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

- Advertisement -