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

user-1178 (google) gravatar 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

Squirrel 1 gravatar image

Squirrel 1
1.6k 1 3

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

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

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



Answers and Comments

SQL Server Central

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



asked: Apr 28, 2010 at 10:01 PM

Seen: 2322 times

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