<[EMAIL PROTECTED]> wrote:
> Or you could do it the easy way in MySQL:
>
> SELECT SEC_TO_TIME( TIME_TO_SEC( OUT ) - TIME_TO_SEC( IN )) AS Hours,
> This requires IN and OUT to be type TIME.

That is a pretty sweet function and it's definitely faster to handle the
conversion in MySQL instead of PHP.  My example was for a datetime MySQL
field as opposed to a plain time field.  Like Rick Widmer stated, usage of
TIME_TO_SEC() only works correctly on time fields.  If your data is a
datetime field you can use UNIX_TIMESTAMP() to convert a field to seconds
since epoch.  Do that for two fields take the difference and divide by a
constant to convert into desired time units.

SELECT UNIX_TIMESTAMP("2001-01-14 16:49:34") => 979508974

--
Steve Werby
COO
24-7 Computer Services, LLC
Tel: 804.817.2470
http://www.247computing.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to