ID EN
Date and Time Functions

TIMEDIFF(expr1,expr2)

MySQL 8.4 🇮🇩 Bahasa Indonesia

TIMEDIFF() mengembalikan expr1 − expr2 dinyatakan sebagai nilai waktu. expr1 dan expr2 adalah string yang dikonversi ke ekspresi TIME atau DATETIME; ini harus dari jenis yang sama setelah konversi. Mengembalikan NULL jika expr1 atau expr2 adalah NULL.

Syntax

MYSQL
SELECT TIMEDIFF('2000-01-01 00:00:00',
                '2000-01-01 00:00:00.000001');
'-00:00:00.000001'
SELECT TIMEDIFF('2008-12-31 23:59:59.000001',
                '2008-12-30 01:01:01.000002');
'46:58:57.999999'

Contoh

Example

The result returned by TIMEDIFF() is limited to the range allowed for TIME values. Alternatively, you can use either of the functions TIMESTAMPDIFF() and UNIX_TIMESTAMP(), both of which return integers.

MYSQL
SELECT TIMEDIFF('2000-01-01 00:00:00',
                '2000-01-01 00:00:00.000001');
'-00:00:00.000001'
SELECT TIMEDIFF('2008-12-31 23:59:59.000001',
                '2008-12-30 01:01:01.000002');
'46:58:57.999999'