Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Time from one field to another 1

Status
Not open for further replies.

briangriffin

Programmer
Nov 6, 2008
878
US
What's the easy way to add the time from column 2 to the date from column 1?

Col 1 Col 2 Needed Result
2010-07-23 00:00:00 1900-01-01 09:41:52 2010-07-23 09:41:52


Thanks in advance...

 
If you just add the time then maybe something like this:
Code:
declare @myt table (col1 datetime, col2 datetime, col3 datetime)
insert into @myt values('7/30/2010', '1900-01-01 09:41:52', null)
select *,  [b]col1 + convert(varchar, col2, 114)[/b]
from @myt

djj
The Lord is My Shepard (Psalm 23) - I need someone to lead me!
 
Mine appears to have cut off the seconds or rounded them...

Any ideas.

Simi


declare @date datetime
declare @time datetime

set @date='2010-07-23 00:00:00'
set @time='1900-01-01 09:41:52'

print DATEDIFF(ss,0,@time)
--34912
print DATEADD(ss,DATEDIFF(ss,0,@time),@date)
--Jul 23 2010 9:41AM

print CONVERT(VARCHAR(26), DATEADD(ss,DATEDIFF(ss,0,@time),@date), 109)
--Jul 23 2010 9:41:52:000AM

print @date + convert(varchar, @time, 114)
--Jul 23 2010 9:41AM

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top