yasmikash
yasmikash

Reputation: 157

How to add 1 hour to a queried time from the database?

I'm a beginner for php and developing this web application, which users who registered on this site, can be claimed some scores in every one hour. When a user claims at some time, database stores that time as time data type in to user_claim_time column. When that same user tries for his next claim, this php script be able to get his last claim time and add one hour to check if the user really claims in an one hour.

So, my question is how can we add one hour to queried time. I'm using php time(h:i:s) function to store server's current time into the database.

Upvotes: 0

Views: 94

Answers (1)

Mahbubul Islam
Mahbubul Islam

Reputation: 1018

You can do something like this:

SELECT * FROM your_table
 WHERE user_claim_time < NOW() - INTERVAL 1 HOUR

However i recommend you to use user_claim_time column in datetime format.

Because time like this '00:00:00' will produce negative output as one hour subtraction can change the date or month as well. For example date like this '2017-08-01 00:00:00'.

So using datetime is the right way i think to properly compare time difference.

Upvotes: 2

Related Questions