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 2012 Forums
 Transact-SQL (2012)
 CHAR TO DATETIME

Author  Topic 

egemen_ates
Yak Posting Veteran

76 Posts

Posted - 2013-03-22 : 08:50:09
Hello Myfrined

i have two column

E_DATE E_TIME
20130322 081104

How can i convert datetime using two columns

result is 2013-03-22 08:11:04.000

thank you

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-03-22 : 09:26:18
http://www.sqlservercurry.com/2011/09/sql-server-concatenate-date-and-time.html


Too old to Rock'n'Roll too young to die.
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-22 : 09:36:23
DECLARE @tabDate TABLE( E_DATE CHAR(8), E_TIME CHAR(6))
INSERT INTO @tabDate VALUES('20130322', '081104')

SELECT CAST ( E_DATE + ' ' + STUFF(STUFF(E_TIME, 3, 0, ':'), 6, 0, ':') AS DATETIME2) FROM @tabDate


--
Chandu
Go to Top of Page
   

- Advertisement -