yahya-236450
Old Hand
Points: 369
More actions
September 12, 2017 at 6:50 pm
#323501
Hi
I need to extract date part from a datetime value and time part from another datetime and combine the two into a new datetime value. How do I do that in T-SQL please?
Thanks
Regards
DesNorton
SSC-Insane
Points: 24569
September 12, 2017 at 10:17 pm
#1959198
This should do the trick.
SELECT NEWDATETIME = DATEADD(DD, DATEDIFF(DD, 0, DATEFIELD1), 0) + CAST(CAST(DATEFIELD2 AS TIME) AS DATETIME)
drew.allen
SSC Guru
Points: 77014
September 13, 2017 at 11:17 am
#1959298
This also works.SELECT DATEADD(DAY, DATEDIFF(DAY, @datetime2, @datetime1), @datetime2)
SELECT DATEADD(DAY, DATEDIFF(DAY, @datetime2, @datetime1), @datetime2)
Drew
J. Drew AllenBusiness Intelligence AnalystPhiladelphia, PA
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply