Shaitan00 Posted November 20, 2008 Posted November 20, 2008 I have a Database (Microsoft SQL Server Express 2005) that contains the following data table: -DATE--------TIME----LEVEL 19/11/2008 - 8:00am - 05 19/11/2008 - 9:00am - 10 20/11/2008 - 8:00am - 06 20/11/2008 - 9:00am - 11 21/11/2008 - 8:00am - 12 ... This data can span as far back as 2-3 months... I want to find a way to return a Dataset for each of the last 7 days. Writing these queries is pretty easy if I know the DATE corresponding to the last 7 days. Is there anyway to calculate such a thing? For example get Now(), then Now()-1, Now()-2, etc... or something similar? Any help would be greatly appreciated. Thanks, Quote
Nate Bross Posted November 20, 2008 Posted November 20, 2008 This will give you today, and the previous six days: for(int i = 0; i > -7; i--) DateTime.Now.AddDays(i); If you are using SQL on a Database you may try something like this: SELECT * FROM TABLE WHERE DateField > StartDate AND DateField < EndDate; I'd probably go for something like the second option. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.