0

In MySQL you can use the DATE_SUB function to get a new date based on the values passed in. For example I can use the following to get the a date of 30 days ago from when I run the function

SELECT DATE_SUB(NOW(), INTERVAL 30 DAY);

Is it possible to use that function or something similar to be able to pull in a value from another config table to determine how many days you want to go back?

SELECT DATE_SUB(NOW(), INTERVAL x DAY);

This is part of a project to move records from live table to an archive table after a set number of days and I would like to be able to set that up as a configureable value.

This is being run as a daily event on a MySQL 5.7 instance that is setup in AWS

1

You can try this:

SELECT DATE_SUB(NOW(), INTERVAL (select interval from yourconfigtable) DAY);
  • That is exactly what I was looking for but couldn't find the syntax. – Joe W Apr 26 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.