March 19, 2013 at 8:25 am
mtassin (3/14/2013)
Toreador (3/14/2013)
Most disappointing. I was sure when I got to the thread I'd see several pages of identical replies saying that it gives an error about assigning variables in the declare statement. What is the world coming to?!I think most of us use SQL 2008 or later versions and are used to it by now. 🙂
That said, this reminds me why I don't use smalldatetime for anything.
Date - yes (just having dates is awesome!)
Time - yes (just having times is also awesome!)
Datetime - yes by default from old stuff (not the coolest, but it generally works)
DateTimeOffset - default for new date/time columns (we have enough localization problems, storing the offset in the datetime helps us avoid new ones).
Shame they did not extend DATEADD to include a time option 🙁
Far away is close at hand in the images of elsewhere.
Anon.
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 6 posts - 31 through 35 (of 35 total)
You must be logged in to reply to this topic. Login to reply