Adding a Time and a Date and then Converting to Timestamp

This is really a few separate issues, but I had to deal with them together, I'll just put them both on this post.

First, I needed to add a time to a date in SQL Server, and then convert the resulting DATETIME to a timestamp. The last line in the select statement below is really doing two things. It essentially converts a string (the date concatenated to the time) into a DATETIME, and then uses the DATEDIFF function to convert to a timestamp.


DECLARE @sometime TIME = '2PM'
DECLARE @somedate DATE = '2012-3-23'

@sometime as SOMETIME,
@somedate as SOMEDATE,
DATEDIFF(second,{d '1970-01-01'}, CONVERT(DATETIME, CONVERT(VARCHAR(10),@somedate) + ' ' + CONVERT(VARCHAR(5),@sometime))) AS TIMESTAMP

Add a Comment...


Comments - 5/25/2017

events-24h bacninhtv intromodeling kratostravel fpsassist toxicskies payfirstsolutions auto-sys cursosiclatam serrurerie - 5/09/2017

Thanks designed for sharing such a pleasant opinion, paragraph is good, thats why i have read it entirely fotballdrakter - 4/26/2017