Suppose you have two columns of character datatype that stores date and time separately and you want to combine both of these columns and convert it to a valid datetime. You can use the following methods:
Consider these variables
declare @date char(8), @time char(8)
select @date='20101001',@time ='12:10:47'
select cast(@date+' '+@time as datetime)
In the above method both of them are combined to form a datetime and converted to datetime datatype
Method 2 : Convert date value into datetime and append time part to it
declare @date char(8), @time char(8)
select @date='20101001',@time ='12:10:47'
select cast(@date as datetime)+@time
In the above method, date value is converted to datetime datatype and time value is
added to it.
3 comments:
We've only just got date and time separately - now you want to put them back together again?
We've only just got date and time separately - now you want to put them back together again?
Post a Comment