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)); Link to comment https://forums.phpfreaks.com/topic/253181-number-of-days-between-now-and-a-date-in-the-future/ 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 Link to comment https://forums.phpfreaks.com/topic/253181-number-of-days-between-now-and-a-date-in-the-future/#findComment-1297970 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" Link to comment https://forums.phpfreaks.com/topic/253181-number-of-days-between-now-and-a-date-in-the-future/#findComment-1298227 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.