Jump to content

Archived

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

juanc

calculating the difference between times

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

Share this post


Link to post
Share on other sites
Why not use the mysql date functions? DATE_ADD and DATE_SUB ?

[a href=\"http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/dat...-functions.html[/a]

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.