Solved

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

Posted on 2008-06-26
2
1,120 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 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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