SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php mysql check if records exist within 3 minutes of now

    How can i do a query to check if any records exist in my mysql table within 3 minutes of the currenct time?

  2. #2
    Twitter: @TimIgoe silver trophy TimIgoe's Avatar
    Join Date
    Feb 2005
    Location
    Blackpool, UK
    Posts
    1,057
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    quite easy, save a timestamp / datetime when you insert a row and then use a limitation of ... timestamp >= NOW() - INTERVAL 3 MINUTE

  3. #3
    SitePoint Zealot Amit Yaron's Avatar
    Join Date
    Jan 2011
    Location
    Hod Haharon, Israel
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By adding a column for creation date, e.g.
    Code:
    creation_date TIMESTAMP,
    Populate it on insertion with CURRENT_TIMESTAMP

    Now, calculate the difference in minutes from the creation date until now using TIMESTAMPDIFF as follows:
    Code:
    SELECT *
    FROM my_table
    WHERE timestampdiff(MINUTE, creation_date, now())<3


Bookmarks

Posting Permissions

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