Re: determining time difference between two timestamp fields.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx> wrote:
> On 25 May 2010 21:50, Bruce Gilbert <webguync@xxxxxxxxx> 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::

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux