How do I do this query in MySQL? (datetime)

Suppose I have a datetime column in MySQL. How do I select all that have a datetime within 2500 seconds of the current datetime?

SELECT ALL where current_datetime - that_datetime < 2500 ...
This question and answers originated from www.stackoverflow.com
Question by (3/17/2010 8:02:55 AM)

Answer

SELECT * FROM Table WHERE that_datetime > NOW() - INTERVAL 2500 SECOND

You want to do all the function calls and operation on constants as MySQL won't use indexes for fields used in any kind of expressions.

Answer by

Find More Answers
Related Topics  mysql  database  query  datetime
Related Questions
  • How do I write this MySQL Query? (datetime)

    Suppose I have a DateTime field called "time_before" I want to insert a datetime that is 1 hour before the now() time. INSERT INTO mytable(time_before) VALUES(now()-3600 seconds)...something l…
  • How do I execute this query in MYSQL?

    Suppose I have a column with words: orange grape orange orange apple orange grape banana How do I execute a query to get the top 10 words, as well as their count?
  • How do I write this GROUP BY query in MYSQL?

    Suppose I have a column called "fruits" I want to select all of the top fruits, ranked by fruits (and group by + count). Fruits: orange orange apple banana apple apple In this case, the selec…
  • How do I modify this query in MYSQL?

    SELECT title, title REGEXP 'apple' as is_fruit FROM mytable; TO: SELECT title, title REGEXP 'apple' or orange...or grapes...as is_fruit... Basically, how do I do an "OR" for REGEXP?
  • How do I format datetime in mySQL?

    I need to capture the date and time in this format: "01/01/11 4:45 PM" Can someone guide me on how to format in this dialog window or is there another method? Many thanks. Erik
  • How do I execute this GROUP BY mysql query?

    Suppose I have a table called "Fruits" with a column called "name". name -------- apple orange orange orange apple grape How can I execute a query to produce this: orange 3 apple 2 grape…
  • How do I run this MySQL JOIN query?

    Let's say I have 2 tables. The first table is a list of personas. A user can have many personas. mysql> select id, user_id, name from personas_personas; +----+---------+--------------+ | id…
  • How do I get PHP variables from this MySQL query?

    I am working on an Asset Database problem using PHP / MySQL. In this script I would like to search my assets by an asset id and have it return all related fields. First I query the database as…
  • How would I do this MySQL query in C#?

    I have 3 tables: KeyWords, GrantsKeyConn, Grants. The way it is set up, each "grant" has associated "keywords", which are stored in the KeyWords table as such: Each "keyword" is associated/co…
  • How do I write this MySQL query?

    I am working on an Asset DB using a lamp stack. In this example consider the following 5 tables: asset, server, laptop, desktop, software All tables have a primary key of id, which is a uni…