Search code examples
sqlsyntaxdateadd

DATE_ADD Function


A glitch in code on my website caused the start date and end date in an sql table to be set to the same day for my online member directory. I have the code glitch corrected, but now need a way to fix the data in the database. I am trying to add a certain number of months (12, 18, 24, etc) to the end_date column depending on the package column. I only want to do this when the start_date column is equal to the end_date column. I have a query started, but keep running into an invalid syntax message. Can someone help? My sql is below

UPDATE porye_jbusinessdirectory_orders
SET end_date = DATE_ADD(months,12,end_date)
WHERE start_date = end_date
AND package_id = 1;

Solution

  • SET end_date = DATE_ADD(start_date, INTERVAL 12 MONTH)

    This is for MySQL.