
February 2nd, 2004, 05:21 AM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 7
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Yeah, I got bored and did it the long way. Here's the code if anyone else might find it useful:
(Cook time is one time value from the database, Prep time is another. This code breaks them into separate hours, mins and seconds, adds them, then converts the result back to hh:mm:ss format)
PHP Code:
// Calculate total time to prepare
// 0=HH, 1=MM, 2=SS
$_prep_time = explode(":", $prep_time);
$_cook_time = explode(":", $cook_time);
// Convert each time to seconds
$prep_seconds = (($_prep_time[0] * 3600) + ($_prep_time[1] * 60) + ($_prep_time[2]));
$cook_seconds = (($_cook_time[0] * 3600) + ($_cook_time[1] * 60) + ($_cook_time[2]));
// Add to produce total
$total = $prep_seconds + $cook_seconds;
// Convert total from seconds to full time again
$_total_time["hrs"] = floor(($total / 3600));
$_total_time["mins"] = floor(($total - ($_total_time["hrs"] * 3600)) / 60);
$_total_time["secs"] = floor(($total - ($_total_time["hrs"] * 3600) - ($_total_time["mins"] * 60)));
// Prefix with 0s where necessary
if (strlen($_total_time["hrs"]) == 1)
$_total_time["hrs"] = "0" . $_total_time["hrs"];
if (strlen($_total_time["mins"]) == 1)
$_total_time["mins"] = "0" . $_total_time["mins"];
if (strlen($_total_time["secs"]) == 1)
$_total_time["secs"] = "0" . $_total_time["secs"];
// Format total time
$total_time = $_total_time["hrs"] . ":" . $_total_time["mins"] . ":" . $_total_time["secs"];
|