Page 1 of 1

Elapsed time in php

Posted: Tue Oct 17, 2006 10:52 pm
by laknal
How can I display elapsed time between created time and submitted time for a order?

Submitted time is timestamp in mysql and created time is {NOW} in php.



Thanks.

Re: Elapsed time in php

Posted: Wed Oct 18, 2006 12:47 am
by Chris Corbyn
laknal wrote:How can I display elapsed time between created time and submitted time for a order?

Submitted time is timestamp in mysql and created time is {NOW} in php.



Thanks.
Are you sure that's not the other way around? In MySQL you'd usually use "NOW()" in a query to get the current timestamp and in PHP you'd use "time()".

PHP's timestamp is the UNIX timestamp (number of seconds since the start of 1970) whereas MySQL uses a structured date format (YYYY-MM-DD-HH-MM-SS). You'll need to convert MySQL's date to a UNIX timestamp using "UNIX_TIMESTAMP(date_column)" and then you can simply get the difference in seconds between what PHP says and what the query says.

It would be nice if PHP provided a built-in library of structured date functions that weren't affected by the UNIX epoch :(