http://feeds.feedburner.com/SpendYourTimeHere-Once

Current Affiares

Wednesday, July 11, 2012

How to get the last 7 days values of a datefield in sql server 2005?

Here is the last 7 days values query without including their time ---
report_mstr = table name
modified_date = datefield


select * from report_mstr 
where (convert(varchar(10),modified_date,120)
between convert(varchar(10),(getdate()-6),120) and convert(varchar(10),getdate(),120))
order by modified_date desc;


 --------
select getdate();
->>>> 2012-07-11 15:41:31.547
select getdate()-6; 
->>>>  2012-07-05 15:40:20.983
select convert(varchar(10),getdate(),120);
->>>> 2012-07-11

No comments:

Post a Comment

My Blog List

Popular Posts

All Rights Reserved To SYTHONCE. Ethereal theme. Powered by Blogger.