Saltar al contenido

¿Cómo puedo actualizar la fecha del campo de fecha y hora solo con mysql?

Solución:

Una opción es usar esto:

UPDATE `calldata`
SET `date` = DATE_SUB(`date`, INTERVAL 7 DAY)
WHERE DATE(`date`) = '2014-01-08'

Violín: http://sqlfiddle.com/#!2/28d71/1

Para un mejor rendimiento, use la siguiente consulta porque MySQL puede usar el índice (si lo hay) como DATE() no está en el lado izquierdo del operador de comparación:

UPDATE `calldata`
SET `date` = DATE_SUB(`date`, INTERVAL 7 DAY)
WHERE `date` >= '2014-01-08'
AND `date` < '2014-01-09

Violín: http://sqlfiddle.com/#!2/7e7b2/1

Prueba esto:

UPDATE calldata
SET date = CONCAT('2014-01-01 ', TIME(date))
WHERE DATE(date) = '2014-01-08'

Comprobar el DEMOSTRACIÓN DE SQL FIDDLE

PRODUCCIÓN

| ID |                           DATE |                       DURATION |     STATUS | DUPLICATION |
|----|--------------------------------|--------------------------------|------------|-------------|
|  1 | January, 01 2014 19:30:12+0000 | January, 01 1970 00:00:03+0000 |    Aborted |      (null) |
|  2 | January, 01 2014 19:30:12+0000 | January, 01 1970 00:00:06+0000 |    Dropped |      (null) |
|  3 | January, 01 2014 05:25:11+0000 | January, 01 1970 00:00:20+0000 |  Connected |    Multiple |
|  4 | January, 01 2014 05:19:21+0000 | January, 01 1970 00:00:21+0000 |  Connected |      Repeat |
|  5 | January, 01 2014 05:12:56+0000 | January, 01 1970 00:00:20+0000 |  Connected |      Unique |
|  6 | January, 01 2014 04:46:56+0000 | January, 01 1970 00:00:41+0000 | Unanswered |    Multiple |
|  7 | January, 01 2014 04:42:56+0000 | January, 01 1970 00:00:35+0000 | Unanswered |      Repeat |
|  8 | January, 01 2014 04:34:56+0000 | January, 01 1970 00:00:31+0000 | Unanswered |      Unique |
|  9 | January, 09 2014 12:06:32+0000 | January, 01 1970 00:00:06+0000 |    Dropped |      (null) |
| 10 | January, 09 2014 12:06:32+0000 | January, 01 1970 00:00:03+0000 |    Aborted |      (null) |
| 11 | January, 09 2014 05:25:11+0000 | January, 01 1970 00:00:20+0000 |  Connected |    Multiple |
| 12 | January, 09 2014 05:19:21+0000 | January, 01 1970 00:00:21+0000 |  Connected |      Repeat |
| 13 | January, 09 2014 05:12:56+0000 | January, 01 1970 00:00:20+0000 |  Connected |      Unique |
| 14 | January, 09 2014 04:46:56+0000 | January, 01 1970 00:00:41+0000 | Unanswered |    Multiple |
| 15 | January, 09 2014 04:42:56+0000 | January, 01 1970 00:00:35+0000 | Unanswered |      Repeat |
| 16 | January, 09 2014 04:34:56+0000 | January, 01 1970 00:00:31+0000 | Unanswered |      Unique |
| 17 | January, 09 2014 12:19:01+0000 | January, 01 1970 00:00:20+0000 |    Aborted |      (null) |
| 18 | January, 09 2014 12:19:01+0000 | January, 01 1970 00:00:19+0000 |  Connected |      Repeat |
| 19 | January, 09 2014 12:15:30+0000 | January, 01 1970 00:00:20+0000 |    Aborted |      (null) |
| 20 | January, 09 2014 12:15:30+0000 | January, 01 1970 00:00:19+0000 |  Connected |      Unique |
| 21 | January, 09 2014 07:25:11+0000 | January, 01 1970 00:00:41+0000 |  Connected |    Multiple |
| 22 | January, 09 2014 07:19:21+0000 | January, 01 1970 00:00:27+0000 |  Connected |      Repeat |
| 23 | January, 09 2014 07:12:56+0000 | January, 01 1970 00:00:20+0000 |  Connected |      Unique |
| 24 | January, 09 2014 06:46:56+0000 | January, 01 1970 00:00:32+0000 | Unanswered |      Unique |
| 25 | January, 09 2014 06:42:56+0000 | January, 01 1970 00:00:29+0000 |    Aborted |      (null) |
| 26 | January, 09 2014 06:34:56+0000 | January, 01 1970 00:00:27+0000 |    Aborted |      (null) |
| 27 | January, 09 2014 05:34:56+0000 | January, 01 1970 00:00:27+0000 |    Aborted |      (null) |
| 28 | January, 09 2014 05:25:11+0000 | January, 01 1970 00:00:41+0000 |  Connected |    Multiple |
| 29 | January, 09 2014 05:19:21+0000 | January, 01 1970 00:00:27+0000 |  Connected |      Repeat |
| 30 | January, 09 2014 05:12:56+0000 | January, 01 1970 00:00:20+0000 |  Connected |      Unique |

UPDATE calldata
SET date="2014-01-01"
WHERE DATE(date) = '2014-01-08'

Demostración de SQLFiddle

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *