November 2, 2015 at 6:24 am
If I have a datetime field, RequestDate, and a time field, DecisionTime, how do I add just the date portion of RequestDate to DecisionTime?
November 2, 2015 at 6:34 am
Something like this
declare @RequestDate datetime = '2015-11-02', @DecisionTime time = '13:29:21.357'
select @RequestDate , @DecisionTime
select
CONVERT(DATETIME,
CONVERT(VARCHAR(10),@RequestDate ,103)
+' '
+CONVERT(VARCHAR(12),@DecisionTime )
)
November 2, 2015 at 6:45 am
Wonderful. Thanx.
November 2, 2015 at 6:53 am
If your datetime column already contains a time and you want to add the time from the time column, you could use this approach.
DECLARE @RequestDate datetime = '2015-11-02',
@DecisionTime time = '13:29:21.357';
SELECT @RequestDate, @DecisionTime, @RequestDate + @DecisionTime;
If your second column is also a datetime, it'll add both parts of both columns together correctly.
November 2, 2015 at 6:55 am
Thanx.
November 2, 2015 at 6:56 am
More than one way to skin a cat and much more slicker, guessing you just get stuck in the ways you have done it in the past.
November 2, 2015 at 10:04 pm
This worked for me
CAST(Tbl.date as DATETIME) + CAST(Tbl.TimeFrom AS TIME)
I have tested this in SQL Server 2008.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply