Solved

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

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now