mysql update all record removing 2 hours from column 1

mysql update all record removing 2 hours from column

UPDATE datetimes
SET datetime = DATE_ADD(datetime,
                        INTERVAL (15 - HOUR(datetime)) HOUR);

Here is what the above code is Doing:
1. Create a new table called datetimes.
2. Insert the datetime column from the original table into the new table.
3. Create a new column called datetime_rounded.
4. Update the datetime_rounded column with the datetime column rounded to the nearest 15 minutes.
5. Update the datetime column with the datetime_rounded column.
6. Drop the datetime_rounded column.

Similar Posts