DrTrans Posted August 18, 2009 Share Posted August 18, 2009 I need some help .. Basically i only want it to get records dated within the last 30 days $query = "SELECT * FROM applicant ORDER BY AppliedDate DESC"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $applicantid = $row['Applicant_ID']; $applicantdate = $row['AppliedDate']; list($adate,$time) = split( " ", $applicantdate, 2 ); $applicantfname = $row['FirstName']; $applicantlname = $row['LastName']; print"<option value=\"$applicantid\">$applicantlname, $applicantfname [ $adate ]</option>"; } [code] This im sure is a simple fix. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/170856-solved-get-records-from-only-30-days-back/ Share on other sites More sharing options...
deansatch Posted August 18, 2009 Share Posted August 18, 2009 Assuiming date is a time() timestamp format $thirty_days_ago = mktime(0,0,0,date("m"),date("d")-30,date("Y")); $query = "SELECT * FROM applicant WHERE AppliedDate >= $thirty_days_ago ORDER BY AppliedDate DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/170856-solved-get-records-from-only-30-days-back/#findComment-901111 Share on other sites More sharing options...
DrTrans Posted August 18, 2009 Author Share Posted August 18, 2009 $applicantdate = 2008-07-18 00:00:00 <-- example Thanks Quote Link to comment https://forums.phpfreaks.com/topic/170856-solved-get-records-from-only-30-days-back/#findComment-901114 Share on other sites More sharing options...
Maq Posted August 18, 2009 Share Posted August 18, 2009 You can do it all in MySQL: SELECT * FROM applicant WHERE AppliedDate >= DATE_SUB(NOW(), INTERVAL 30 day) ORDER BY AppliedDate DESC; Quote Link to comment https://forums.phpfreaks.com/topic/170856-solved-get-records-from-only-30-days-back/#findComment-901115 Share on other sites More sharing options...
deansatch Posted August 18, 2009 Share Posted August 18, 2009 I made a bad assumption. Doh! Quote Link to comment https://forums.phpfreaks.com/topic/170856-solved-get-records-from-only-30-days-back/#findComment-901117 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.