I am trying to have a page list all records that have a date of current date till 5 days in the past the code below is what I have came up with although the result is all records not the ones specified: $date = date("Y-m-d"); $newdt = strftime('%Y-%m-%d', strtotime("-5 days")); echo "<center><font size=\"4\" color=\"Teal\"><b><u>Recently Added and Approved Users</u></b></font><hr>"; echo "<table width=\"800\" cellspacing=\"3\" cellpadding=\"3\" border=\"0\">"; $res = mysql_query("SELECT * FROM `users` WHERE `dateadded`>=".$newdt." && `approval`=1") or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ echo "<tr><td id=\"heading2\"><li> <a href=\"userdesc.php?siteid=".$row['userid']."\">".$row['username']."</a> - </td><td>".$row['userdesc']."</td></tr>"; } echo "</table>"; Code (markup): Submission of the registration for saves the date into a mysql table (date field) the following way: $date = date("Y-m-d"); Any help would be great and thank you ahead of time
What you're doing is probably the easiest way to do it. You can have mysql calculate the date by using the built in date functions. http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html The easiest way to do it within php would probably be like this: $res = mysql_query("SELECT * FROM `users` WHERE `dateadded`>= ". date("Y-m-d",strtotime("-5 Days")) ." && `approval`=1") or die(mysql_error());
ok I have changed to your post and it still displays records with the date of 2009-01-18 which is the earliest date that I have in the db. It should stop at 2009-01-21. Am I correct in assuming that the field type in mySQL db should be set to date as well (thats how I have it).