Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Only Retrieve Data from 1 Week Ago from a Table 1

Status
Not open for further replies.

kernal

Technical User
Feb 27, 2001
415
US
I have table where data is uploaded to it every day but I only want to retrieve the data from 1 week ago. I'd be running this report twice a week. Example:

Today is Friday, 04/10/2015 so I only want data from that table that was uploaded on Friday, 04/03/2015.
If I run this query on Tuesday, 04/14/2015 then I only want data from that table that was uploaded on Tuesday, 04/07/2015.

Help is very appreciated.

Thank you
 
Hi

Use [tt]date_sub()[/tt] :
Code:
[b]select[/b]
[teal]*[/teal]

[b]from[/b] the_table

[b]where[/b] the_field [teal]=[/teal] date_sub[teal]([/teal]curdate[teal](),[/teal] interval [purple]1[/purple] week[teal])[/teal]

Feherke.
feherke.ga
 
Code:
select  *
from    tablename
where   date_sub(now() interval 1 week) > cast(DateTimeField as Date)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top