How would I go about updating the dates in a MySQL table to the first day of the month?
For example, the data looks like this:
1 2013-01-13
2 2013-02-11
3 2013-02-01
4 2013-01-30
5 2013-03-27
...and I would like it to look like this...
1 2013-01-01
2 2013-02-01
3 2013-02-01
4 2013-01-01
5 2013-03-01
You can convert it to string to get the year and month and concatenate it with 01
.
UPDATE tableName
SET dateField = CONCAT(DATE_FORMAT(dateField, '%Y-%m-'), '01')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With