vickytam Posted March 18, 2006 Share Posted March 18, 2006 Hi!I am trying to write a code for counting time differnet between a date (get from a database, MySQL, format:"yyyy-mm-dd hh:mm:ss) and current date&time. But I cannot generate the result. Any one can help? Thanks. e.g: date& time from database : 2006-03-10 12:00:00 current date&time : 2006-03-11 23:00:00I wanna the output is " 1 day 11 hours 00 mins or 1 days 11:00 hoursThanks,Vicky Link to comment https://forums.phpfreaks.com/topic/5229-date-time-comparedifferent/ Share on other sites More sharing options...
kenrbnsn Posted March 18, 2006 Share Posted March 18, 2006 Here's a script I wrote a while ago to do that:[code]<?php $minute = 60; $hour = 60 * 60; $day = $hour * 24; $now = strtotime('now'); $start = strtotime('2006-03-10 12:00:00'); $seconds_left = $now - $start; $days_left = floor($seconds_left / $day); $hours_left = floor(($seconds_left % $day)/$hour); $minutes_left = floor((($seconds_left % $day) % $hour) / $minute); echo 'Start: ' . date('m/d/Y G:i',$start) . "<br />\n"; echo 'End: ' . date('m/d/Y G:i',$now) . "<br />\n"; echo 'There are ' . $days_left . ' days, ' . $hours_left . ' hours and ' . $minutes_left . ' minutes left';?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/5229-date-time-comparedifferent/#findComment-18590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.