Re: determining time difference between two timestamp fields.

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

 



yea, not sure why my Query isn't returning a value though? If I don't
use date(), what should I use?

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,

sorry for the top-posting, but I think you have to in gmail.


On Tue, May 25, 2010 at 3:14 PM, Peter Lind <peter.e.lind@xxxxxxxxx> wrote:
> On 25 May 2010 21:09, Bruce Gilbert <webguync@xxxxxxxxx> wrote:
>> the resulting output with that code is a little weird. I get September
>> 3, 1970 2:39:32pm
>>
>> I think part of the problem is my Query. When I run it in PHP MyAdmin
>> I get a null value for login_timestamp even though there is indeed a
>> timestamp there. The Query again is:
>>
>> SELECT Responses.editor_name,Answer1,Answer2,Answer3,Answer4,Answer5,Answer6,Answer7,Answer8,Answer9,Answer10,Answer11,Answer12,submit_timestamp,login_timestamp
>>        FROM Responses LEFT JOIN Candidates USING (user_id)
>>
>> login_timestamp is in a table called 'Candidates' and submit_timestamp
>> is in a tables called 'Responses'.
>>
>> thanks for all the help to this point.
>>
>> On Tue, May 25, 2010 at 2:28 PM, Ashley Sheridan
>> <ash@xxxxxxxxxxxxxxxxxxxx> wrote:
>>> On Tue, 2010-05-25 at 14:22 -0400, Bruce Gilbert wrote:
>>>> 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>";
>>>
>>> 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>";
>>>
>
> There are two problems you're looking at. The first is the null value
> you're getting, which will invalidate the whole thing. The second
> problem is that you were looking for output along the lines of "60
> minutes" but you're using date() which as the second parameter expects
> a unix timestamp - not two timestamps subtracted from each other.
>  On another note, subtracting the output of two strtotime() calls
> inside the date() call doesn't amount to subtracting anything from a
> string.
>
> Regards
> Peter
>
> --
> <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