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 Quote Link to comment 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 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.