Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Query Date/Time Question

    hello,
    I'm trying to query users that have been on the site in the last 15 minutes from a date time feild in a mysql data base.

    I can do this already with php code, but would like to do it right from the select statement, but i'm not exactly sure how or where to start.

    any ideas/examples would be great!

    thanks in advance for your time,
    -Ken

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can use the date_sub function, like this:

    PHP Code:
    $query "
    SELECT *
    FROM your_table
    WHERE your_timestamp > date_sub(CURRENT_TIMESTAMP , INTERVAL 15 MINUTE) 
    This code says get all rows with a timestamp greater than this moment minus 15 minutes.

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    kool!
    thats what i was looking for

    thanks!
    -Ken


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •