Hello.

Tell me how to implement the following.
The script will run on the crown, which from a certain database table (dates, status) should pull out all values ​​that are older than a month from the current date. The date in the dates field is stored in unixtime and puts these records in the status field to inactive.

That is, as I understand it, you need to get the current date at unixtime, then get the date a month earlier (-2678400), and if the value in dates is less than or equal to it, then set the status to inactive. Help with the code in terms of sql query, frozen.

  • tsya.ru - etki
  • I know, I was in a hurry ... PS I am the winner of the regional Olympiad in the Russian language .. true in the distant past))) I scold myself, but now I am typing faster than I think))) - Batyabest

1 answer 1

Help with the code in terms of the sql query is frozen.

UPDATE tbl_name SET status = 'inactive' WHERE dates <= :deadline 

where :deadline is replaced by the received timestamp.

You can reduce the number of records being updated (I have no idea how this will affect performance):

 UPDATE tbl_name SET status = 'inactive' WHERE dates <= :deadline AND status != 'inactive' 
  • And is the deadline just obtained by taking away from the current date the number of seconds in a month? Instead of a deadline variable set? - Batyabest
  • @Batyabest, yes - etki