Q:

form value 00:00:00 into time value

I was wondering, if I record a time through a javascript function and say I leave it on for 2 mins 20 seconds:
00.02.20

now when I insert this into my database, where the field type is set as time, it doesn't record properly.
I think it comes from how I request the data:
$length = mysql_escape_string($_REQUEST['timeDrive']);

is there a way of converting this into a time that is going to output the exact value:
00.02.20

thanks for the help!

A:

If you don't need to perform any mathematical functions on those fields (eg: sum, average, etc), and it's purely for display, then you can just store it as plain text in a CHAR(8) field.
Otherwise, you'll need to normalise it to some sort of unit. I'd suggest maybe as an integer of the total number of seconds (if that is accurate enough for you).
To convert to seconds:
 $val = "00.02.20";
 $parts = explode(".", $val);   // ['00', '02', '20']
 $totalSeconds = parts[0] * 3600 + parts[1] * 60 + parts[2]; // 140

And to convert it back:
$seconds = 140; // this would be read from the database, or something

printf("%02d.%02d.%02d",
    $seconds / 3600,
    ($seconds / 60) % 60,
    $seconds % 60
);

