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'

SELECT
@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

http://koreadunamis.org/xe/index.php?mid=a0305b&document_srl=1164353 http://gestionandote.org/contratacion-de-una-consultoria-para-el-desarrollo-de-un-mapeo-de-politicas-publicas-para-mujeres-rurales-implementadas-en-paises-de-america-latina-y-el-caribe/ http://sntvnews.com/2016/02/11/munasabad-lagu-soo-dhaweynayay-wasiiro-iyo-xildhibano-ka-tirsan-dowlad-gobaleedka-koonfur-galbeed-ayaa-lagu-qabtay-magalaada-nairobi/ http://iparte.com/blogs/14633/14772/jurgen-klopp-sa-utseendet-billige-fotballdra - 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