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.
Elapsed time in php
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Elapsed time in php
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()".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.
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