Solved

MYSQL: How to query yyyy-mm-dd hh:mm:ss MINUS 4 hours ago?

Posted on 2008-06-26
2
1,125 Views
Last Modified: 2013-12-12
MYSQL


Hello,

I have a field in my mysql table in this format: yyyy-mm-dd hh:mm:ss

How do I retrieve rows that are "current time MINUS 4 hours"? That is, I want to retrieve anything with a timestamp that is less than 4 hours ago.

How do I write this mysql query?

Thanks.
0
Comment
Question by:gingera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
CoyotesIT earned 500 total points
ID: 21875804
try something like:

SELECT <your_date_time_field> FROM <your_table> WHERE <your_date_time_field> >= DATE_SUB(NOW(), INTERVAL 4 HOUR);

I don't have any data to test that on, but I think that should get you pointed in the right direction.

~CoyotesIT
0
 

Author Closing Comment

by:gingera
ID: 31471000
THANKS!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question