PHP: Days, hours and minutes left to a certain date? -
i'm trying remaining days, hours , minutes date using php.
however strange output code looks this:
-16828 days , -11 hours , -21 minutes , -24 seconds
the future dates stored in mysql database in format:
29/01/2016 7pm
so went ahead , done this:
$draw_time = "29/01/2016 7pm"; $date = $draw_time; $timestamp = strtotime($date); $new_date = date('y-m-d a',$timestamp ); $seconds = strtotime($new_date) - time(); $days = floor($seconds / 86400); $seconds %= 86400; $hours = floor($seconds / 3600); $seconds %= 3600; $minutes = floor($seconds / 60); $seconds %= 60; echo "$days days , $hours hours , $minutes minutes , $seconds seconds";
but when run code, above strange output!
i understand because of number reasons thing think of fact using a
in format?
could please advise on issue?
simply use datetime
class as
$draw_time = "29/01/2016 7pm"; $date = datetime::createfromformat("d/m/y ha",$draw_time); $date2 = new datetime(); echo $diff = $date2->diff($date)->format("%a days , %h hours , %i minutes , %s seconds");
Comments
Post a Comment