Re: determining time difference between two timestamp fields.
| From: | Bruce Gilbert | Date: | Tue, 25 May 2010 21:03:45 +0000 |
| Subject: | Re: determining time difference between two timestamp fields. | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-305526@lists.php.net to get a copy of this message | ||
thanks again for all the help.
>The output of strtotime() is an int - specifically a number of
>seconds. Subtract two number of seconds from each other and what do
>you get? Furthermore, divide by 60 and what do you get?
> Should you want to format this, you can consider sprintf(), though,
>if you just want a whole number of minutes, just use floor().
I am using floor() now instead of date()
> Try just selecting all values from your database, to see what's
> actually in there.
I found out the problem.the value in (user_id) in the two tables has
to be the same. That is why the Query wasn't working.
I still am not getting the desired result though. Something that
should be displaying as five minutes displays as -117 minutes
My current code.
$submit_time = strtotime($row['submit_timestamp']);
$login_time = strtotime($row['login_timestamp']);
$completion_time = $submit_time - $login_time;
$completion_time /= 60;
$formatted_completion_time = floor($completion_time );
echo "<tr><th class='complete'>Completion
Time:</th></tr><tr><td>";
echo $formatted_completion_time;
echo " minutes";
echo "</td></tr>";
On Tue, May 25, 2010 at 3:54 PM, Peter Lind <peter.e.lind@gmail.com> wrote:
> On 25 May 2010 21:50, Bruce Gilbert <webguync@gmail.com> wrote:
>> yea, not sure why my Query isn't returning a value though? If I don't
>> use date(), what should I use?
>
> The output of strtotime() is an int - specifically a number of
> seconds. Subtract two number of seconds from each other and what do
> you get? Furthermore, divide by 60 and what do you get?
> Should you want to format this, you can consider sprintf(), though,
> if you just want a whole number of minutes, just use floor().
>
>> the SQL for the timestamps looks like this.
>>
login_timestamp datetime NOT NULL default '0000-00-00
>> 00:00:00',
>> submit_timestamp timestamp NOT NULL default
>> CURRENT_TIMESTAMP,
>
> Try just selecting all values from your database, to see what's
> actually in there.
>
>> sorry for the top-posting, but I think you have to in gmail.
>
> No you don't, that's ridiculous.
>
> --
> <hype>
> WWW: http://plphp.dk /
> http://plind.dk
> LinkedIn: http://www.linkedin.com/in/plind
> BeWelcome/Couchsurfing: Fake51
> Twitter: http://twitter.com/kafe15
> </hype>
>
--
::Bruce::