x

Is there a way to add a date and time together to get the datetime value in SQL?

I have a date field, and a separate time field, that I want to concatenate or add together in SQL. For example, if my date field has 01-01-2010 and my time field has 12:00:00, I want to combine them or convert them into a datetime value of 01-01-01 12:00:00. Is this possible?

more ▼

asked Apr 28, 2010 at 10:01 PM in Default

avatar image

user-1178 (google)
1 2 2 2

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Yes. Try

declare @date datetime, @timestr varchar(10)

select @date = '2010-04-01',
@timestr = '12:34:56'

select @date + ' ' + ' ' + @timestr

more ▼

answered Apr 29, 2010 at 04:48 AM

avatar image

Squirrel 1
1.6k 1 3 5

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x2091
x81
x37
x36

asked: Apr 28, 2010 at 10:01 PM

Seen: 3093 times

Last Updated: Apr 28, 2010 at 10:01 PM

Copyright 2016 Redgate Software. Privacy Policy