View Single Post
Old 22-Oct-2007, 12:44 AM   #2 (permalink)
Anilrgowda
Administrator
 
Anilrgowda's Avatar

Posts: 18,715
Join Date: Jan 2006
Rep Power: 10 Anilrgowda is on a distinguished road

IM:
Default Re: MS SQL Server 2000 - DATE & TIME Ranges - Week & Month

current week:
where datepart(wk,[open_time] = datepart(getdate()) and year(open_time)=year(getdate())

Last week
where datepart(wk,[open_time] = case when datepart(wk,getdate())>1 then datepart(wk,getdate())-1 else 52 end and year([open_time]) = case when datepart(wk,getdate())>1 then year(getdate()) else year(getdate())-1

current month
where month(open_time) = month(getdate()) and year(open_time)=year(getdate())

last month
where month(open_date)=case when month(getdate())=1 then 12 else month(getdate())-1 and
year(open_date)=case when month(getdate())=1 then year(getdate())-1 else year(getdate())

In order to specify that the week starts on Saturday, put SET DATEFIRST 6 before your SELECT.


------------------


Anilrgowda is offline   Reply With Quote