Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
How can i get one week data from sql using getdate . yesterday date get from below attched code using. Date field datatype is date ,price fied datatype is float .
SQL
select Date,price 
from  dataupload 
where  MONTH(date)=MONTH(GETDATE()-1)
and  day(date)=day(getdate()-1)
Posted
Updated 28-Jun-15 21:06pm
v2

Try this-
SQL
SELECT [Date],Price 
FROM Dataupload 
WHERE [Date] BETWEEN DATEADD(DAY,-8,GETDATE()) AND DATEADD(DAY,-1,GETDATE())


Hope, it helps :)
 
Share this answer
 
First, read out the various date time function in SQL https://msdn.microsoft.com/en-sg/library/ms186724.aspx#[^], specifically, getdate() and day(). To get tomorrow date, use getdate()+1, extend this to get the date a week from now.
Next, to get data between 2 dates, use BETWEEN in SQL https://msdn.microsoft.com/en-sg/library/ms186724.aspx#[^]
 
Share this answer
 
v2

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