philipfwilson
philipfwilson

Reputation: 757

Update MYSQL timestamp column but not greater than now()

I need to update a mysql timestamp column but not greater then today with an update statement.

  SELECT invoice, last_tested_date, (last_login_date + INTERVAL + 1100 DAY) as updated_date 
  FROM test.testApp 
  order by updated_date desc;

I want to add 1100 days to the last_tested_date. I don't want that timestamp column last_tested_date to be greater than now();

How can I do this with a simple update statement.??

Thanks Phil

Upvotes: 1

Views: 31

Answers (1)

Giorgos Betsos
Giorgos Betsos

Reputation: 72165

Try this:

UPDATE testApp
SET last_tested_date = LEAST(DATE_ADD(`last_login_date`, INTERVAL 1100 DAY), NOW());

Demo here

Upvotes: 2

Related Questions