Now we're getting somewhere.
In SQL Server, there is a GetDate() function. This returns the current date and time of the server that SQL Server is running on. You can use GetDate(), but remember that it also returns the time. If you do date calculations, the time will "go with it". For example, you can simply subtract 30 from GetDate(), but the time will be unchanged.
Select GetDate()-30 As ThirtyDaysAgo
You can remove the time component from GetDate() like this...
Select DateAdd(Day, DateDiff(Day, 0, GetDate()), 0)
So.... the beginning of the day, 30 days ago would look like this:
Select DateAdd(Day, DateDiff(Day, 0, GetDate()-30), 0)
So, your query would be something like....
Code:
Select Count(*)
From YourTable
Where SomeDate >= DateAdd(Day, DateDiff(Day, 0, GetDate()-30), 0)
And SomeDate < GetDate()
Anyone working with dates should become familiar with the DateAdd and DateDiff functions. If you are not already familiar with these two functions, I encourage you to spend a couple minutes learning about them.
-
George
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom