x
login about faq Site discussion (meta-askssc)

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 '10 at 10:01 PM in Default

user-1178 (google) gravatar image

user-1178 (google)
1 1 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 '10 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.

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



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x1602
x84
x28
x17

asked: Apr 28 '10 at 10:01 PM

Seen: 1509 times

Last Updated: Apr 28 '10 at 10:01 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.