Create SQL timer column

Asked

Viewed 234 times

0

Is it possible to do a timer column, which calculates 24 hours? For example, PHP starts this timer in this column, and until it resets the user is prevented from performing such an action. However, when it Zera, it goes back to 24:00:00 and only starts when the user runs the process which can only be done every 24 hours.

Update: I managed to add the table to date and time perfectly. I’m just wondering how to compare this date recorded in SQL and the current date to see if it’s been 24 hours...

Picture of the SQL table:

inserir a descrição da imagem aqui

1 answer

1


I think it’s easier to solve this with a datetime column. So PHP queries the column, checks whether more than 24 hours have passed between the current date and the column date, and does what it has to do. Then update the column with the current date.

  • I did as you said. But now as I compare the two to see if it’s been 24 hours?

  • You can use the function date_diff() if you have PHP 5.3+, but you can do this directly in sql using the query SELECT TIMEDIFF(NOW(), last_vote).

  • Interesting this function TIMEDIFF. And she returns in hours the result?

  • @William the easiest way to see the output of the function is to do a test in Mysql. the function returns the time between the two dates, with hours, minutes and seconds...

  • I used the method of friend Blunt above. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.