March 19, 2013 at 8:37 am
David Burrows (3/19/2013)
Shame they did not extend DATEADD to include a time option 🙁
They didn't need to. DATEADD has always supported time options.
March 19, 2013 at 11:55 am
Hugo Kornelis (3/19/2013)
David Burrows (3/19/2013)
Shame they did not extend DATEADD to include a time option 🙁They didn't need to. DATEADD has always supported time options.
Sorry I meant an option to add TIME data type instead of having to convert TIME to seconds and then adding to DATETIME data type or converted DATE data type.
Far away is close at hand in the images of elsewhere.
Anon.
March 19, 2013 at 5:06 pm
David Burrows (3/19/2013)
Sorry I meant an option to add TIME data type instead of having to convert TIME to seconds and then adding to DATETIME data type or converted DATE data type.
For a minute I misunderstood you again, thinking that you wanted to be able to use DATEADD to add, for instance, two hours to a value of datatype TIME. Which, again, is possible.
But then it dawned me that you want to be able to create a datetime value out of a data and a time. And you are right - there should be an easy way to do this, yet there isn't. I think this is the shortest you can do:
DECLARE @d date = '20130320';
DECLARE @t time = '13:05';
SELECT DATEADD(second, DATEDIFF(second, '0:00', @t), CAST(@d AS datetime));
April 15, 2013 at 12:43 am
It was real good question. 🙂
June 16, 2015 at 3:03 am
Just on the edge
Viewing 5 posts - 31 through 35 (of 35 total)
You must be logged in to reply to this topic. Login to reply