January 26, 2011 at 3:11 pm
If not I guess I can create my own udf. Thanks
SELECT something
FROM someentity
WHERE DATEPART(MONTH, somedate) = DATEPART(MONTH, GETDATE())
AND DATEPART(YEAR, somedate) = DATEPART(YEAR, GETDATE())
January 26, 2011 at 3:17 pm
Here's how I'd do it:
SELECT something
FROM someentity
WHERE somedate>= DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)
Please note that I removed the datepart function from the source column to make it SARG-able (= to allow for an index seek instead of a scan assuming there's an index that could be used).
January 26, 2011 at 3:25 pm
you are a genius.
i forgot my code won't be using an index with that datepart.
thanks!
January 26, 2011 at 3:30 pm
SQL Iron Chef (1/26/2011)
you are a genius.i forgot my code won't be using an index with that datepart.
thanks!
:blush:
Naah... I'm just trying to return what I've learned over the years hanging around here. 😉
So: Glad I could help 😀
January 26, 2011 at 8:54 pm
For some other date manipulation functions, look here: Some Common Date Routines.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply