Jump to content

date & time compare/different


vickytam

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.