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? Quote Link to comment 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); Quote Link to comment 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! 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.