Re: Time problem

From: Date: Thu, 08 Feb 2001 13:32:55 +0000
Subject: Re: Time problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-38749@lists.php.net to get a copy of this message
<php3@developersdesk.com> 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/

« previous php.general (#38749) next »