Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 794013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:14:49+00:00 2026-05-14T22:14:49+00:00

I have a table that contains the next columns: ip(varchar 255), index(bigint 20), time(timestamp)

  • 0

I have a table that contains the next columns:

ip(varchar 255), index(bigint 20), time(timestamp)

each time something is inserted there, the time column gets current timestamp.
I want to run a query that returns all the rows that have been added in the last 24 hours.
This is what I try to execute:

SELECT ip, index FROM users WHERE ip = 'some ip' AND TIMESTAMPDIFF(HOURS,time,NOW()) < 24

And it doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:14:50+00:00Added an answer on May 14, 2026 at 10:14 pm

    HOURS should be HOUR. See the documentantion for TIMESTAMPADD to see the valid values of the unit parameter:

    TIMESTAMPADD(unit,interval,datetime_expr)

    Adds the integer expression interval to the date or datetime expression datetime_expr. The unit for interval is given by the unit argument, which should be one of the following values: FRAC_SECOND (microseconds), SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.

    So your query should be:

    SELECT ip, index
    FROM   users
    WHERE  ip = 'some ip'
    AND    TIMESTAMPDIFF(HOUR, time, NOW()) < 24
    

    Note also that this query won’t be able to take advantage of an index on time, if one exists. It could be more efficient to rewrite the query as follows:

    SELECT ip, index
    FROM   users
    WHERE  ip = 'some ip'
    AND    time > NOW() - interval 1 day
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that contains the following columns: ID int, DISTANCE float, EVENT
I have a table that contains common entries in two columns. For Example: Column1
I have a table that contains multiple dropdown menus for a list of profile
I have a table that contains all the data about users . Users can
I have a table that contains the stock. It's legacy database and the stock
I have a table that contains a record of prioritys that links to another
I have a table that contains an Id column as a primary key. There
I have a table that contains userids and their score. eg. userid rating 123
I have a table that contains intervals: CREATE TABLE tbl ( user_id: INTEGER, start:
I have a table that contains id, created, user_id. I'm wondering if there is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.