May 17, 2011 at 8:41 am
Ya, I just realized that I'm picking only in the same month... sorry about that.
Thanks Michael.
May 18, 2011 at 4:26 pm
Ninja's_RGR'us,
Cool way to get just the date from today. I'd never seen that before. So, I tested it.
DECLARE @test_dt DATETIME
set @test_dt = DATEDIFF(D, 0, GETDATE());
SELECT @test_dt
SET @test_dt = DATEADD(D, 0, DATEDIFF(D, 0, GETDATE())) --Today without time
SELECT @test_dt
Both SELECT statements produced the same result.
Is the DATEADD necessary? Am I missing something?
LC
May 18, 2011 at 5:13 pm
try it with assigning the result to a variable... there's a implicit cast in there you're not seeing.
May 19, 2011 at 12:11 pm
I am missing something.
Are my "SET" statements not assignments?
DECLARE @test_dt DATETIME
SET@test_dt = DATEDIFF(D, 0, GETDATE());
SELECT@test_dt
DECLARE @x DATETIME
SET@x = @test_dt
SELECT@x
Both "SELECT" statements produce the same "timeless" timestamp.
LC
May 19, 2011 at 12:24 pm
Lee Crain (5/19/2011)
I am missing something.Are my "SET" statements not assignments?
DECLARE @test_dt DATETIME
SET@test_dt = DATEDIFF(D, 0, GETDATE());
SELECT@test_dt
DECLARE @x DATETIME
SET@x = @test_dt
SELECT@x
Both "SELECT" statements produce the same "timeless" timestamp.
LC
The point that was being made is that the following statement results in an implicit cast of the integer result of the DATEDIFF function to a datetime value.
SET @test_dt = DATEDIFF(D, 0, GETDATE());
The result is the same as this with the implict conversion made explicit:
SET @test_dt =convert(datetime,DATEDIFF(D, 0, GETDATE()));
May 19, 2011 at 6:33 pm
Oh, got it. Glad I didn't need to be clubbed over the head with it.
:hehe:
LC
Viewing 6 posts - 16 through 20 (of 20 total)
You must be logged in to reply to this topic. Login to reply