lukelee Posted October 15, 2010 Share Posted October 15, 2010 Hi, Currently I am making a module for joomla. every article has an publish date, if the article was published in 7 days ago, it will displayed as "article in last week", My idea is to use today's date - publish date, if the result is greater than 7 and smaller than 14, the article will be displayed as "article in last week. Any one know how to write this code? Here is what I have got, but not working. <?php $todays_date = date("Y-m-d"); $result = mysql_query("select * from jos_content where $test between $todays_date-14 and $todays_date-7"); while($row = mysql_fetch_array($result)) { echo "$todays_date - $row[title]"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/215925-compare-current-date-with-the-date-in-database/ Share on other sites More sharing options...
abdfahim Posted October 15, 2010 Share Posted October 15, 2010 Use your SQL QUERY like $result = mysql_query("select * from jos_content where DATEDIFF(publish_date,'".$todays_date."') between 7 AND 14); Quote Link to comment https://forums.phpfreaks.com/topic/215925-compare-current-date-with-the-date-in-database/#findComment-1122408 Share on other sites More sharing options...
lukelee Posted October 15, 2010 Author Share Posted October 15, 2010 ah, it works, thanks man. What if I want to display the articles before 7days? can I write :" between 7 AND 100000" Quote Link to comment https://forums.phpfreaks.com/topic/215925-compare-current-date-with-the-date-in-database/#findComment-1122413 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.