lukep11a Posted December 14, 2011 Share Posted December 14, 2011 Hi, I am trying to get the number of days between the current date and a date in the future specified by column 'end_date'. The code I have seems to be working but it displays the number of days as a negative number, how do I change this to be a positive number? I have tried simply changing $days = $now - $end_date; to $days = $end_date - $now; but that doesn't work as I thought it would! Thanks in advance.. $now = time(); $end_date = strtotime($row['end_date']); $days = $now - $end_date; echo floor($days/(60*60*24)); Quote Link to comment Share on other sites More sharing options...
xyph Posted December 14, 2011 Share Posted December 14, 2011 Use MySQL to do this... check out DATEDIFF() http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff Quote Link to comment Share on other sites More sharing options...
lukep11a Posted December 15, 2011 Author Share Posted December 15, 2011 Thanks for pointing me in the right direction, managed to sort it simply with "SELECT DATEDIFF(end_date, CURDATE()) as days" Quote Link to comment 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.