meds
meds

Reputation: 22926

MYSQL query to get all entries with specific time, from PHP?

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..

Upvotes: 0

Views: 424

Answers (1)

bigredbob
bigredbob

Reputation: 1857

MySQL does this quite nicely:

SELECT * FROM something WHERE timestamp > DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 DAY) 

Upvotes: 2

Related Questions