Jump to content


Photo

date & time compare/different


  • Please log in to reply
1 reply to this topic

#1 vickytam

vickytam
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 18 March 2006 - 04:02 PM

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:00

I wanna the output is " 1 day 11 hours 00 mins or 1 days 11:00 hours


Thanks,
Vicky



#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 18 March 2006 - 04:39 PM

Here's a script I wrote a while ago to do that:
<?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';
?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users