tags:

views:

34

answers:

2

Hi,

I inserted a number of rows 3 hours ago and I don't want these rows from changing. How can I write sql statement that compare current time with the timstamp in the row and restrict users from changing it if abouve creteria is met.

Thanks

+2  A: 

You can use a WHERE clause in all updates:

UPDATE yourtable
SET foo = bar
WHERE inserttime > NOW() - interval 3 hour
Mark Byers
+4  A: 

If you want to do it by using mysql, you will have to use the INTERVAL statement which will allow you to "add" time to date functions... for instance:

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

You can find more info and examples here: Date and Time Functions

Cristian
I think there is some mistake in query? Shouldn't it be Now() - Interval 3 HOUR?
Ankit Rathod
Yes... my mistake... thanks :D
Cristian