Friday, August 15, 2014

SQL - How to update one field of existing date

 Let's say we want to set all salary dates to 1st of the month from an environment where it was staggered for different people at different days of the month.
To update an existing date in such a way, that only one of the field of the date is changed and rest all remain constant (Tested in Mysql).
update employee set salary_date = 
STR_TO_DATE(concat(month(salary_date),'-',01,'-',YEAR(salary_date)), '%m-%d-%Y') ;
Note that only the month field is replaced here.

No comments:

Post a Comment