June 16, 2017 at 1:33 pm
Hello,
I have 2 column first column in this Format YYYYMMDD and second column as HHMM i want one column as datetime.
First column as = 20170612
Second column = 1345
I want date time as 2017-06-12 13:45
Thank you.
June 16, 2017 at 1:41 pm
sks_989 - Friday, June 16, 2017 1:33 PMHello,I have 2 column first column in this Format YYYYMMDD and second column as HHMM i want one column as datetime.
First column as = 20170612
Second column = 1345I want date time as 2017-06-12 13:45
Thank you.
One question, what happens with times before 10AM? Is there a leading zero or no?
June 16, 2017 at 1:45 pm
there will be leading 0 like this way 0930 or 0700
June 16, 2017 at 2:21 pm
sks_989 - Friday, June 16, 2017 1:45 PMthere will be leading 0 like this way 0930 or 0700
Then it's easy. Here's an example on how to do it.
DECLARE @Sample TABLE(
DateCol char(8),
TimeCol char(4),
DatetimeCol datetime
)
INSERT INTO @Sample VALUES( '20170612', '1345', NULL)
SELECT *, CAST( DateCol + ' ' + STUFF( TimeCol, 3, 0, ':') AS datetime)
FROM @Sample;
UPDATE @Sample SET
DatetimeCol = CAST( DateCol + ' ' + STUFF( TimeCol, 3, 0, ':') AS datetime)
SELECT *
FROM @Sample
June 19, 2017 at 12:34 pm
Thanks Luis it worked.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply