웹이야기

MySQL TIMESTAMPDIFF() 본문

D/MySQL

MySQL TIMESTAMPDIFF()

yeon.Biju 2020. 4. 4. 19:40

MySQL 날짜함수, 시간함수

 

TIMESTAMPDIFF()

   -

 

 

TIMESTAMPDIFF(unit, datetime_expr1, datetime_expr2)

의 형태

 

Returns datetime_expr2 - datetime_expr1, where datetime_expr1 and datetime_expr2 are date or datetime expressions. One expression may be a date and the other a datetime: a date value is treated as a datetime having the time part '00:00:00' where necessary. The unit for the result (an integer) is given by the unit argument. The legal values for unit are the same those listed in the description of the TIMESTAMPADD function.

 

mysql> SELECT TIMESTAMPDIFF(MONTH, '2020-04-01', '2020-10-01');
+--------------------------------------------------+
| TIMESTAMPDIFF(MONTH, '2020-04-01', '2020-10-01') |
+--------------------------------------------------+
|                                                6 |
+--------------------------------------------------+
1 row in set (0.00 sec)

 

 


mysql> SELECT TIMESTAMPDIFF(YEAR, '2020-04-01', '2020-10-01');
+-------------------------------------------------+
| TIMESTAMPDIFF(YEAR, '2020-04-01', '2020-10-01') |
+-------------------------------------------------+
|                                               0 |
+-------------------------------------------------+
1 row in set (0.00 sec)

 

 

mysql> SELECT TIMESTAMPDIFF(SECOND, '2020-04-01 05:34:55', '2020-10-10 23:32:55');
+---------------------------------------------------------------------+
| TIMESTAMPDIFF(SECOND, '2020-04-01 05:34:55', '2020-10-10 23:32:55') |
+---------------------------------------------------------------------+
|                                                            16653480 |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)

'D > MySQL' 카테고리의 다른 글

MySQL TIME_TO_SEC()  (0) 2020.04.05
MySQL TIME_FORMAT()  (0) 2020.04.04
MySQL TIMESTAMPADD()  (0) 2020.04.04
MySQL TIMESTAMP()  (0) 2020.04.04
MySQL TIMEDIFF()  (0) 2020.04.03
Comments