Forum Moderators: coopster

Message Too Old, No Replies

Displaying array with date constraints

PHP & mySQL

         

RussellC

9:18 pm on Dec 13, 2002 (gmt 0)

10+ Year Member



I am using a while loop to diplay the contents of an table:

while ($row = @mysql_fetch_array($query))

Each row has a cell that carries the date. How can I make it only display the last 30 days worth of rows?

As always, Thanks for the help :)

mavherick

9:44 pm on Dec 13, 2002 (gmt 0)

10+ Year Member



Well it all depends on the format of your date field. I personally use the unix time since 1970 thingy (number of seconds since 1970), and if you also do you could build your sql query like this:

SELECT *
FROM yourTable
WHERE date > $timeLimit

$timeLimit would be number of second since 1970 at runtime minus 30 days worth of second.

hope that helps

mavherick

RussellC

12:01 am on Dec 14, 2002 (gmt 0)

10+ Year Member



my date is in this format : 2002-12-13 12:34:56

how would I do that?

andreasfriedrich

1:00 am on Dec 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use the following condition in your where clause:

WHERE (to_days(now()) - to_days(date)) <= 30

Andreas