Jump to content

calculating the difference between times


juanc

Recommended Posts

Hi can someone help me please,

My goal is to add to different times into two different mySQL columns (in the same row and inputted one after the other) then calculate the number of minutes in between each.

For each column I input using strftime('%H %M', time())

Then I used this function to calculate the difference

[code]

function DateDiff
($interval,$date1,$date2) {
    // get the number of seconds between the two dates
$timedifference = $date2 - $date1;

    switch ($interval) {
        case 'w':
            $retval = bcdiv($timedifference,604800);
            break;
        case 'd':
            $retval = bcdiv($timedifference,86400);
            break;
        case 'h':
            $retval =bcdiv($timedifference,3600);
            break;
        case 'n':
            $retval = bcdiv($timedifference,60);
            break;
        case 's':
            $retval = $timedifference;
            break;
            
    }
    return $retval;

}


[/code]

Then I did

[code]

echo DateDiff('n',$row[start],$row[end]);
[/code]

but it just gives back 0 .............at the same time I'll add that the mysql columns I originally had as varchar then changed them to time

hope someone can help
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.