ID EN
Date and Time Functions

NOW([fsp])

MySQL 8.4 🇮🇩 Bahasa Indonesia

Mengembalikan tanggal dan waktu saat ini sebagai nilai dalam format 'YYYY-MM-DD hh:mm:ss' atau YYYYMMDDhhmmss, bergantung pada apakah fungsi tersebut digunakan dalam konteks string atau numerik. Nilainya dinyatakan dalam zona waktu sesi.

Syntax

MYSQL
SELECT NOW();
'2007-12-15 23:50:26'
SELECT NOW() + 0;
20071215235026.000000

Contoh

Example

If the fsp argument is given to specify a fractional seconds precision from 0 to 6, the return value includes a fractional seconds part of that many digits.

MYSQL
SELECT NOW();
'2007-12-15 23:50:26'
SELECT NOW() + 0;
20071215235026.000000
Example 2

NOW() returns a constant time that indicates the time at which the statement began to execute. (Within a stored function or trigger, NOW() returns the time at which the function or triggering statement began to execute.) This differs from the behavior for SYSDATE(), which returns the exact time at which it executes.

MYSQL
SELECT NOW(), SLEEP(2), NOW();
+---------------------+----------+---------------------+
| NOW()               | SLEEP(2) | NOW()               |
+---------------------+----------+---------------------+
| 2006-04-12 13:47:36 |        0 | 2006-04-12 13:47:36 |
+---------------------+----------+---------------------+

SELECT SYSDATE(), SLEEP(2), SYSDATE();
+---------------------+----------+---------------------+
| SYSDATE()           | SLEEP(2) | SYSDATE()           |
+---------------------+----------+---------------------+
| 2006-04-12 13:47:44 |        0 | 2006-04-12 13:47:46 |
+---------------------+----------+---------------------+