Jump to content

Archived

This topic is now archived and is closed to further replies.

vickytam

date & time compare/different

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.