Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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,127 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 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