Restrict users from changing rows inserted 3 hours ago in mysql

I inserted a few lines 3 hours ago and I do not want these lines to change. How can I write a sql statement that will compare the current time with a timestamp in a string and prevent users from changing it if the above criteria are met.

thank

+3
source share
2 answers

If you want to do this with mysql, you will need to use a statement INTERVALthat will allow you to “add” functions from time to time ... for example:

UPDATE table
SET data = 'whatever'
WHERE NOW() - INTERVAL 3 HOUR  < last_change

Here you can find additional information and examples: Date and time functions

+5
source

WHERE :

UPDATE yourtable
SET foo = bar
WHERE inserttime > NOW() - interval 3 hour
+2

Source: https://habr.com/ru/post/1748702/


All Articles