![]() |
MySQL Time +24 hours
Hello,
I have a MySQL timestamp column in my table, problem is, i want to see if any are older than 24 hours, how would i be able to do that with the MySQL timestamp? Thanks. |
Code:
SELECT fields FROM table WHERE ts_field >= ts_field+(60*60*24) |
sql Code:
|
There are a whole bunch of functions available in MySQL to play around with dates: MySQL Date & Time Functions
|
Yeah, I was digging in my MySQL reference book, since Srev got me interested, and I think this would be a better method:
sql Code:
That makes it a whole lot simpler than what I thought of before. However it does require MySQL 5.0 and upwards. |
You could also play around with DATE_ADD/SUB, for example:
SELECT DATE_SUB(NOW(), INTERVAL 24 HOUR) AS 24_hours_ago; |
Hmm... oddly enough none of them seemed to of worked :s
I have MySQL5+ too |
When you say none worked, could you provide us with some details; exact queries used, your exact MySQL version, copy/paste error messages, etc?
|
Well Salathe, yours thinks every date is older than 24 hours :s, any ideas?
|
What query are you using?
|
SELECT *
FROM `my_rss_feeds` WHERE DATE_SUB( NOW( ) , INTERVAL 24 HOUR ) LIMIT 0 , 30 |
After a quick chat on IRC, we settled on using:
DATE_SUB(NOW(), INTERVAL 24 HOUR) > rsstimestamp (where rsstimestamp is the TIMESTAMP column). :) |
| All times are GMT. The time now is 12:34 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0