Forum Moderators: coopster

Message Too Old, No Replies

only show records within 30 days of todays date

         

JuiceUK

2:16 pm on May 25, 2006 (gmt 0)

10+ Year Member



Hi,

I have a database wit ha date field in it. I have a promotional spot on my home page. The date in the database is the date that I want the promotion to run. I want to run a query that only brings back the records that are within 30 days of todays date. I've tried various date manipulation stuff in mysql but not got it wot work just right.

Can anyone help?

Thanks,

barns101

2:50 pm on May 25, 2006 (gmt 0)

10+ Year Member



If the data in the database is a Unix timestamp, you can work out which records to show based on the fact that 30 days is 2592000 seconds. Your code would look something like this:


$thirty_days_ago = mktime()-2592000; // Current Unix timestamp minus thirty days
SELECT * FROM `table` WHERE `date` > $thirty_days_ago;