Elapsed time in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
laknal
Forum Newbie
Posts: 21
Joined: Wed Oct 11, 2006 7:38 pm

Elapsed time in php

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Elapsed time in php

Post 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 :(
Post Reply