TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-09-2009, 03:34 PM   #1 (permalink)
The Contributor
 
webosb's Avatar
 
Join Date: Nov 2007
Posts: 41
Thanks: 24
webosb is on a distinguished road
Default I need help with a query to get the amount of minutes from DATETIME

So I have a column called "signupdate" that is a datetime datatype. And I want to be able to get the elapsed time it took between signups of a user with the same ip address. I never formulated datetime datatypes before, can anyone offer any assistance?

say if i had rows of data as so:

ipaddress|signupdate
10.10.1.100|2009-04-08 22:20:01
10.10.1.100|2009-04-08 22:23:12
10.10.1.100|2009-04-08 22:24:30
10.10.1.100|2009-04-08 22:25:32
10.10.1.100|2009-04-08 22:26:16


SELECT (FORMULA TO GET ELAPSED TIME [HIGHEST VAL - LOWEST VAL])
FROM users
WHERE ipaddress = "10.10.1.100"

Basically to do this and output 6 minutes:
22:26:16 - 22:20:01 = 6:15

I'm getting stuck on how to get the highest value and lowest value from the 5 rows of data
I
__________________
"Things you can get access to, you should never memorize." -Albert Einstein
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
webosb is offline  
Reply With Quote
Old 04-09-2009, 03:50 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

You should be able to use the ORDER BY clause to get them the way you want.
__________________

Village Idiot is offline  
Reply With Quote
Old 04-09-2009, 03:55 PM   #3 (permalink)
The Contributor
 
webosb's Avatar
 
Join Date: Nov 2007
Posts: 41
Thanks: 24
webosb is on a distinguished road
Default

So are you saying that I should use sub-selects to put out the values together into 1 query to do the math?
__________________
"Things you can get access to, you should never memorize." -Albert Einstein
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
webosb is offline  
Reply With Quote
Old 04-09-2009, 04:12 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

I misread your question at first, but that would be one way of doing it.
__________________

Village Idiot is offline  
Reply With Quote
Old 04-09-2009, 05:25 PM   #5 (permalink)
The Contributor
 
webosb's Avatar
 
Join Date: Nov 2007
Posts: 41
Thanks: 24
webosb is on a distinguished road
Default

I was able to get it to work with this query:

SELECT
round(
(
(SELECT unix_timestamp(signupdate) FROM users WHERE ipaddress = "10.10.1.100" ORDER BY signupdate DESC LIMIT 1)
-
(SELECT unix_timestamp(signupdate) FROM users WHERE ipaddress = "10.10.1.100" ORDER BY signupdate ASC LIMIT 1)
)/60) as elapsed
FROM users
WHERE ipaddress = "10.10.1.100" LIMIT 1;

i doubt that it's the most optimized way of doing it but it works..
__________________
"Things you can get access to, you should never memorize." -Albert Einstein
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
webosb is offline  
Reply With Quote
Old 04-09-2009, 07:51 PM   #6 (permalink)
The Contributor
 
Sakakuchi's Avatar
 
Join Date: Feb 2009
Posts: 64
Thanks: 1
Sakakuchi is on a distinguished road
Default

Wrote this some time ago - makes actually the same - (But looks quite messy...)

PHP Code:
    public function protectBruteforce()
  {
        
$ip $this->getUserIP();
        
$core = new core;
        
$query sprintf("SELECT * FROM log_failed_login WHERE IP = '%s' AND `time` > '%s' LIMIT 0,7",
        
$core->cleanSQL($ip), time() - 600);
        
$result mysql_query($query) or die('Could not perform query.');
        if(
mysql_num_rows($result) > 6)
    {
            die(
'loginLimitExceeded');
        }
        
mysql_free_result($result);
    } 
Sakakuchi is offline  
Reply With Quote
Old 04-10-2009, 11:46 AM   #7 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

I would also store the date/time as a unix timestamp (integer).
maZtah is offline  
Reply With Quote
Old 04-10-2009, 11:51 AM   #8 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by maZtah View Post
I would also store the date/time as a unix timestamp (integer).

That's how I store my dates, it's easier for me to manipulate and do calculations this way....
allworknoplay is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Full Text Searches with Query Expansion Orc MySQL & Databases 4 12-19-2008 08:39 PM
Query With a C# Variable?‏ StevenF The Lounge 5 12-08-2008 05:32 AM
Ugh, Query in a while statement Aaron Absolute Beginners 2 08-11-2008 06:36 PM
query question Evulness Absolute Beginners 4 04-21-2008 07:46 PM
Query caching xenon Advanced PHP Programming 4 01-29-2008 08:20 PM


All times are GMT. The time now is 04:24 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design