ankycooper Posted August 4, 2008 Share Posted August 4, 2008 hi ??? I Have a table named prop_tbl with a lot of feilds, one of the feilds is create_date which stores the timestamp of the record creation. Now i want to pull up the records which are x months old. please help $months=10; $nowstamp=time(); $expirestamp=strtotime("-$months month",$nowstamp); "SELECT * FROM prop_tbl WHERE create_date<='$expirestamp'" but it simply thows all the records Please help I just want records whose create_date is greater than equal to $months Link to comment https://forums.phpfreaks.com/topic/118090-simple-date-query-from-mysql/ Share on other sites More sharing options...
eludlow Posted August 4, 2008 Share Posted August 4, 2008 Do you want to show all the records that are OLDER than 10 months? If so then I'd have thought: $tenMonthOldTimestamp = time() - 24192000; (number of seconds in ten months..) then mysql_query("SELECT * FROM `prop_tbl` WHERE create_data <= ' $tenMonthOldTimestamp'"); E Link to comment https://forums.phpfreaks.com/topic/118090-simple-date-query-from-mysql/#findComment-607545 Share on other sites More sharing options...
ankycooper Posted August 4, 2008 Author Share Posted August 4, 2008 Hey Thanks for replying... But How did you get the number.....24192000. i want to pull up $months intervals.... $months can be 10 Months or 1 Month Or 12 Months ... I mean Anything Looking Forward For help Link to comment https://forums.phpfreaks.com/topic/118090-simple-date-query-from-mysql/#findComment-607551 Share on other sites More sharing options...
The Little Guy Posted August 4, 2008 Share Posted August 4, 2008 The date column needs to be in a timestamp format. $months = 5; $sql = mysql_query("SELECT * FROM users WHERE `date` < DATE_SUB(NOW(),INTERVAL $months MONTH) AND `date` > DATE_SUB(NOW(),INTERVAL ".($months + 1)." MONTH)"); Link to comment https://forums.phpfreaks.com/topic/118090-simple-date-query-from-mysql/#findComment-607552 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.