ID EN
Date and Time Functions

DATE_FORMAT(date,format)

MySQL 8.4 🇮🇩 Bahasa Indonesia

Memformat nilai tanggal sesuai dengan string format. Jika salah satu argumennya adalah NULL, fungsi akan mengembalikan NULL.

Syntax

MYSQL
SELECT DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y');
'Sunday October 2009'
SELECT DATE_FORMAT('2007-10-04 22:23:00', '%H:%i:%s');
'22:23:00'
SELECT DATE_FORMAT('1900-10-04 22:23:00',
                '%D %y %a %d %m %b %j');
'4th 00 Thu 04 10 Oct 277'
SELECT DATE_FORMAT('1997-10-04 22:23:00',
                '%H %k %I %r %T %S %w');
'22 22 10 10:23:00 PM 22:23:00 00 6'
SELECT DATE_FORMAT('1999-01-01', '%X %V');
'1998 52'
SELECT DATE_FORMAT('2006-06-00', '%d');
'00'

Contoh

Example

The specifiers shown in the following table may be used in the format string. The % character is required before format specifier characters. The specifiers apply to other functions as well: STR_TO_DATE(), TIME_FORMAT(), UNIX_TIMESTAMP().

MYSQL
SELECT DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y');
'Sunday October 2009'
SELECT DATE_FORMAT('2007-10-04 22:23:00', '%H:%i:%s');
'22:23:00'
SELECT DATE_FORMAT('1900-10-04 22:23:00',
                '%D %y %a %d %m %b %j');
'4th 00 Thu 04 10 Oct 277'
SELECT DATE_FORMAT('1997-10-04 22:23:00',
                '%H %k %I %r %T %S %w');
'22 22 10 10:23:00 PM 22:23:00 00 6'
SELECT DATE_FORMAT('1999-01-01', '%X %V');
'1998 52'
SELECT DATE_FORMAT('2006-06-00', '%d');
'00'