Forum Moderators: open

Message Too Old, No Replies

Mysql Query Help

selecting entries from the past week

         

wfernley

1:49 pm on Jun 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey everyone,

I still trying to get used to the Mysql date function but I need help generating my query.

I want to create a query that will pull entries from the past 7 days. I have a TIMESTAMP column in my table that records the date like this: 2006-06-19 11:12:01

How can I create a query that will look at those dates and grab any entries from the past week?

Thanks in advance for your help!

Wes

coopster

3:59 pm on Jun 20, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There are a number of ways to get the past 7 days. Basically though, you want any row where your date column is greater than today's date less 7 days. Here is a related thread that shows some examples:
View results where date less than 14 days old [webmasterworld.com]

wfernley

7:25 pm on Jun 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Great! Thanks for the reply.

I was able to get this working:

date_added > DATE_SUB(CURDATE(), INTERVAL 7 DAY)