Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 concatnate date and time

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-10-29 : 05:19:25
i have 2 sql fields - one called thedate one called thetime

(both are datetime field)

how can i set mydate=the date from the date and the time from thetime

Kristen
Test

22859 Posts

Posted - 2007-10-29 : 06:03:36
Just add them together?

DECLARE @thedate datetime,
@thetime datetime

SELECT @thedate = '20071029',
@thetime = '10:02:12.123'

SELECT [@thedate] = @thedate,
[@thetime] = @thetime,
[Combined] = @thedate + @thetime

Kristen
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-10-29 : 06:15:46
problem is both have a date and time -- and i want to ignore the time by the thedate and ignore the date by thetime

so for example


DECLARE @thedate datetime,
@thetime datetime

SELECT @thedate = '20071029 10:02:12.123',
@thetime = '18801010 10:02:12.123'

SELECT [@thedate] = @thedate,
[@thetime] = @thetime,
[Combined] = @thedate + @thetime

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-10-29 : 06:24:34
Please post sample data with your question in future, it saves answer the wrong question

DECLARE @thedate datetime,
@thetime datetime

SELECT @thedate = '20071029 01:02:03:123',
@thetime = '20000102 10:02:12.123'

SELECT [@thedate] = @thedate,
[@thetime] = @thetime,
[Combined] = DATEADD(Day, DATEDIFF(Day, 0, @thedate), 0)
+ (@thetime - DATEADD(Day, DATEDIFF(Day, 0, @thetime), 0))

Kristen
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-10-29 : 06:28:56
thanks :)
Go to Top of Page
   

- Advertisement -