Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-06-26
2
Medium Priority
?
1,128 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
2 Comments
 
LVL 8

Accepted Solution

by:
CoyotesIT earned 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

972 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