MySQL - Change date to the first day of the month

Viewed 159

Is there any way I can change the date in MySQL?

For example, I have a column with dates and they look like:

2020-12-14

I want to change the dates so that I can change all dates to the first of the month but keeping the year and month as is, like so:

2020-12-01 
2 Answers

You can use subtraction:

update t
    set datecol = datecol + interval (1 - day(datecol)) day;

To the first day, d1 is 01 everytime.

UPDATE [table]
   SET dateField = CONCAT(YEAR(dateField),'-',MONTH(dateField),'-01')
 WHERE [conditions]
Related