Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date query

Author  Topic 

lemondash
Posting Yak Master

159 Posts

Posted - 2008-01-21 : 08:20:17
Afternoon all !!!

Was wondering if somebody could help me am trying to write a sql query, but i'm trying to do is run a searh with a where cluase that only brings back data for the current month. And every other time i run it it will do the same. I know i can use this for results from yesterday "cast(convert(varchar(8),getdate()-1,1) as datetime)"

Any help would be great.

Lee

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-21 : 08:23:05
[code]datecol >= dateadd(month, datediff(month, 0, getdate()), 0) and
datecol <= dateadd(month, datediff(month, 0, getdate()) + 1, -1)[/code]



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

lemondash
Posting Yak Master

159 Posts

Posted - 2008-01-21 : 08:25:48
Excellent many thanks
Go to Top of Page
   

- Advertisement -