Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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,

Posted

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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...