'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 1:[1]

If I understand you correctly, you want to use DATEADD instead.

Your syntax seems like DATEADD (datepart , number , date ) which is not the syntax for DATE_ADD

UPDATE porye_jbusinessdirectory_orders
SET end_date = DATEADD(month, 12 ,end_date)
WHERE start_date = end_date
AND package_id = 1;

Check more here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 James