Thank you very much Erik, I'll try it  :)

anyway, it would be nice to know what's wrong with the code I posted, why
does it work with CHAR and not with TIME types?


From: "Erik Price" <[EMAIL PROTECTED]>
> First of all, if you're storing time then you're better off using the
> DATETIME column type.  Even though it may take a bit more space than
> CHAR(8), unless you absolutely need the ultimate in table optimization,
> use DATETIME.  It makes comparisons and manipulations like the one you
> are trying to do much easier.  (Because you can convert them to
> UNIX_TIMESTAMP and then do your math on that, which is a piece of cake.)
> But to answer your question, here's what I would do:
> // $db contains database connection handle
> $sql = "SELECT row FROM table WHERE where_clause";
> // attempt to pull data from DB
> if (!$result = mysql_query($sql, $db)) {
> die('Query failed.');
> }
> // assuming only one row is returned
> $row = mysql_result($result, 0);
> $time_array = explode(':', $row);
> $hours = $time_array[0];
> $minutes = $time_array[1];
> $seconds = $time_array[2];
> // convert to timestamp so we can easily do math
> $timestamp = mktime($hours, $minutes, $seconds, 0, 0, 0);
> Now all of your times are in timestamp form, and you can do what you
> need to do.

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to