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...



I was wondering if you ever thought of changing the page layout of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or two pictures. Maybe you could space it out better? - 6/28/2017

Hello there! This post couldn't be written any better! Going through this article reminds me of my previous roommate! He always kept talking about this. I most certainly will send this post to him. Pretty sure he'll have a very good read. I appreciate you for sharing! - 6/20/2017 - 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