Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how we can display last 7 days data from database give sql query for problem
Posted

SQL
DECLARE @Now DATETIME = GETDATE();
DECLARE @7DaysAgo DATETIME = DATEADD(day,-7,@Now);

SELECT *
FROM   emp
WHERE  date BETWEEN @7DaysAgo AND @Now
ORDER  BY date
 
Share this answer
 
Chk this,

Select * from yourtablename where yourdatecolumnname<=DATEADD(day,-7,getdate())
 
Share this answer
 
Comments
King Fisher 27-Mar-14 1:37am    
i think,the query must be >=DATEADD(day,-7,getdate())
To get the last 7 days records from table

SQL
select *from tbl_payment where paid_date between  dateadd(DAY,-7,GETDATE()) and getdate()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900