Re: determining time difference between two timestamp fields.
| From: | Nathan Rixham | Date: | Tue, 25 May 2010 19:18:17 +0000 |
| Subject: | Re: determining time difference between two timestamp fields. | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-305519@lists.php.net to get a copy of this message | ||
Ashley Sheridan wrote:
On Tue, 2010-05-25 at 14:22 -0400, Bruce Gilbert wrote:Ash is right :) If I may add a little observation, this (and many things like it) may be easier to approach and debug if you handle just one operation at a time; break it down in to little chunks. For instance: $submit_time = strtotime($row['submit_timestamp']); $login_time = strtotime($row['login_timestamp']); $completion_time = $submit_time - $login_time; $completion_time /= 60; $formatted_completion_time = date('F j, Y g:i:sa', $completion_time ); echo "<tr><th>Completion Time:</th></tr><tr><td>"; echo $formatted_completion_time; echo "</td></tr>"; Sure it's verbose, but it's also so much easier to debug, and you can always tidy / crunch it up afterwards. Best, Nathanecho "<tr><th>Completion Time:</th></tr><tr><td>". date('F j, Y g:i:sa',strtotime($row['submit_timestamp']) - strtotime($row['login_timestamp']))/60 , "</td></tr>";There's a good reason for that! What you're actually doing is this: echo "<tr><th>Completion Time:</th></tr><tr><td>" . date('F j, Y g:i:sa',strtotime($row['submit_timestamp']) - strtotime($row['login_timestamp'])) / 60 , "</td></tr>"; You're trying to divide a string by 60, because date() returns a string. Put that division inside the brackets for date() rather than outside. It might help to break up that whole line of output into several parts. Put the date into a variable and then just output the HTML line: $date = date('F j, Y g:i:sa', (strtotime($row['submit_timestamp']) - strtotime($row['login_timestamp']))/60); echo "<tr><th>Completion Time:</th></tr><tr><td>$date</td></tr>";