tags:

views:

71

answers:

1

I'm trying to query a mysql table which places its date in the following format: yyyy-mm-dd hh:mm:ss

So it's date and time, and that's all in a single field.

Now from php I want to get the time and query the table to only return entries where the date field is less than 24 hours old.

I'm having issues with the system because PHPs get time seems to return the values seperately and I'm struggling to figure out how to make it work with mysql queries.

This seems fairly simple but I'm quite new to php so sorry if I'm completely missing something..

+2  A: 

MySQL does this quite nicely:

SELECT * FROM something WHERE timestamp > DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 DAY) 
bigredbob
bigredbob's suggestion works great as long as the database server and the php server's date and time are the same. Basically, his point is that you don't have to pass the query a date time constant from PHP, just let MySQL calculate what "24 hours old" is.
Marcus Adams