NOW() - INTERVAL 1 MINUTE not working

Im using an event stream to check a DB table to see if there are new entries. If the entry was submitted within a minute ago I want to get this data and then send it back to display.

Im using this code:

  $query = "SELECT * FROM student_art WHERE created > NOW() - INTERVAL 1 MINUTE";

created is a timestamp that I have in each table row.
For some reason this is not working and it is retrieving the FIRST record in my DB and displaying it every few seconds.

what kind of timestamp? what’s the DATATYPE?

Created is type Datatime

if you meant DATETIME, then your query should work fine, and return all rows less than a minute old, not just one of them

what’s the “first” row anyway? rows in a table do not have a sequence

By first row I mean the first table row entry…with ID = 1. And yes I meant datetime.

do me a favour and run your query directly in the database, not via your application language (php?)

i’ll bet it works there

1 Like

it retrieves the last row but that entry was inserted a few hours ago…BUT I just noticed that the timestamp is different than my current local time. When I use NOW() in my query…what time is that?? It almost looks like NOW and the servers timestamp are different time zones?

The timestamp for that record is 2019-10-23 13:16:15. Which is still a couple hours out for my locally? Could that be the problem?

hmmm… :thinking:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.