Subtract a day on all dates within 5 months

Asked

Viewed 20 times

0

Good morning, I need to subtract a day from all the data of the bank in the period of 5 months and update the bank with these new values. The query below returns the data already discounted one day:

SELECT DATE_SUB(DateAndTime, INTERVAL 1 DAY) FROM floattablediario 
  WHERE DateAndTime between '2020-01-01' AND '2020-05-26'
  AND TagIndex = 0
order by DateAndTime asc;

If I update based on this query, it does not update all data:

UPDATE floattablediario SET DateAndTime = DATE_SUB(DateAndTime, INTERVAL 1 DAY)
  WHERE DateAndTime between '2020-01-01' AND '2020-05-26'
  AND TagIndex = 0
order by DateAndTime asc;

How could I do this update?

1 answer

0


USE THE DATE(expr FUNCTION)

 UPDATE floattablediario SET DateAndTime = DATE_SUB(DateAndTime, INTERVAL 1 DAY)
  WHERE DATE(DateAndTime) between '2020/01/01' AND '2020/05/26'
    AND TagIndex = 0

Browser other questions tagged

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