DATE_DIFF
Calcula la diferencia entre dos marcas de tiempo.
Sintaxis
DATE_DIFF(UNIT, TIMESTAMP1, TIMESTAMP2)
Argumentos
UNIT
Tipo: string
La unidad de tiempo que se va a devolver.
Puede ser una de las siguientes:
yearquartermonthweekdayhourminutesecondmillisecond
TIMESTAMP1
Tipo: timestamp
El tiempo que se va a restar de TIMESTAMP2.
TIMESTAMP2
Tipo: timestamp
La fecha-hora TIMESTAMP1 de la que se resta.
Devuelve
Tipo: bigint
TIME2 - TIME1 expresado en términos de UNIT.
Ejemplos
| UNIT | TIMESTAMP1 | TIMESTAMP2 | Resultado |
|---|---|---|---|
| día | 2001-08-22 03:04:05.321
|
2001-08-23 03:04:05.321
|
1 |
| year | 2001-08-22 03:04:05.321
|
2006-08-22 03:04:05.321
|
5 |
| year | 2006-08-22 03:04:05.321'
|
2001-08-22 03:04:05.321
|
-5 |
| second | 2001-08-22 03:04:05.321
|
2001-08-22 03:04:35.321
|
30 |
| quarter | 2001-08-22 03:04:05.321
|
2001-11-22 03:04:05.321
|
1 |
| quarter | 2001-08-22 03:04:05.321
|
2001-08-22 03:04:05.321
|
0 |
| year | 2001-08-22 03:04:05.321
|
null
|
null
|