DATE_DIFF
Calcola la differenza tra due timestamp.
Sintassi
DATE_DIFF(UNIT, TIMESTAMP1, TIMESTAMP2)
Argomenti
UNIT
Tipo: string
L'unità di tempo da restituire.
Può essere una delle seguenti:
yearquartermonthweekdayhourminutesecondmillisecond
TIMESTAMP1
Tipo: timestamp
Il tempo da sottrarre a TIMESTAMP2.
TIMESTAMP2
Tipo: timestamp
Il tempo da cui viene sottratto TIMESTAMP1.
Restituisce
Tipo: bigint
TIME2 - TIME1 espresso in termini di UNIT.
Esempi
| UNITÀ | TIMESTAMP1 | TIMESTAMP2 | Output |
|---|---|---|---|
| giorno | 2001-08-22 03:04:05.321
|
2001-08-23 03:04:05.321
|
1 |
| anno | 2001-08-22 03:04:05.321
|
2006-08-22 03:04:05.321
|
5 |
| anno | 2006-08-22 03:04:05.321'
|
2001-08-22 03:04:05.321
|
-5 |
| secondo | 2001-08-22 03:04:05.321
|
2001-08-22 03:04:35.321
|
30 |
| trimestre | 2001-08-22 03:04:05.321
|
2001-11-22 03:04:05.321
|
1 |
| trimestre | 2001-08-22 03:04:05.321
|
2001-08-22 03:04:05.321
|
0 |
| anno | 2001-08-22 03:04:05.321
|
null
|
null
|