proud Posted February 22, 2010 Share Posted February 22, 2010 I need help with subtracting two dates from each other and getting the result in days. $current_time= strtotime("now"); $current_date= date('Y-m-d',$current_time); $query = mysql_query("SELECT * FROM books where isbn='$isbn' and date_due < '$current_date' ") or die(mysql_error()); $fetch= mysql_fetch_array($query); $due_date=$fetch['date_due']; $diff_date=$current_date-$due_date; echo"This book has been delayed for ".$diff_date." days"; Where the value of $current_date is 2010-02-22 and the value of $due_date is 2010-02-20 So how can I get the value of $diff_date to be 2 days? Link to comment https://forums.phpfreaks.com/topic/192921-help-with-subtracting-two-dates-from-each-other/ Share on other sites More sharing options...
jl5501 Posted February 22, 2010 Share Posted February 22, 2010 $diffsecs = strtotime($currentDate) - strtotime($dueDate); $diffdays = floor(diffsecs / 60 / 60 / 24); Link to comment https://forums.phpfreaks.com/topic/192921-help-with-subtracting-two-dates-from-each-other/#findComment-1016072 Share on other sites More sharing options...
proud Posted February 22, 2010 Author Share Posted February 22, 2010 $diffsecs = strtotime($current_date) - strtotime($due_date); $diffdays = floor($diffsecs / 60 / 60 / 24); Thankyou very much jl5501, this one did the job! Link to comment https://forums.phpfreaks.com/topic/192921-help-with-subtracting-two-dates-from-each-other/#findComment-1016078 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.