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 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"; 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 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; 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! 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
Archived
This topic is now archived and is closed to further replies.