Skip to content
Advertisement

Select a record when the timestamp has passed by a certain amount of time MYSQL/PHP

I’m trying to select sessions that are younger than 6 hours old with this query like so:

JavaScript

The problem is that the query condition is always false and never manages to find the sessions even when a record actually has a timeStamp of a few seconds ago.

obviously I am very sure that the problem is in the condition of the:

tStamp < DATE_SUB (CURRENT_TIMESTAMP, INTERVAL 6 HOURS)


I insert the data records in the table like this:
JavaScript

I thought the problem was the formatting of the date but I don’t think since the insert works well and the date is correctly inserted in the DB.

This is the sql structure of the table:

JavaScript

Where could the problem be? Why does the condition never come true?

Sample record: enter image description here

So as in this case, I’m trying to fetch this record since the timeStamp is less than 6 hours old with the query I showed; the problem is that the return query is null, it is as if there were no records that have a timeStamp younger than 6 hours (even if it is older it does not work)

Advertisement

Answer

To solve this problem I used this query:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement