TIMESTAMPDIFF

Stai visualizzando una vecchia versione di questo article. Visualizza la versione più recente.

Sintassi

TIMESTAMPDIFF(unità, espr1, espr2)

Description:

Restituisce il risultato di espr2 - espr1, che sono entrambe di tipo DATETIME. Una espressione potrebbe essere una data e un'altra un datetime; in questo contesto, un valore DATE viene considerato come un DATETIME che ha come orario '00:00:00'. Il risultato è un intero e l'unità di misura è quella specificata dall'argomento unità. I valori ammessi sono gli stessi che si possono usare per la funzione TIMESTAMPADD().

Esempi

 
MariaDB [(none)]> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01');
+------------------------------------------------+
| TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01') |
+------------------------------------------------+
|                                              3 |
+------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01');
+-----------------------------------------------+
| TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01') |
+-----------------------------------------------+
|                                            -1 |
+-----------------------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55');
+----------------------------------------------------------+
| TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55') |
+----------------------------------------------------------+
|                                                   128885 |
+----------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> 

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.