DATE_FORMAT()

Overview

Returns a date value as a string using the given format.

USAGE

DATE_FORMAT(date, format)

Argument Name

Description

date

The date to format

format

The format to apply

DETAILS

DATE_FORMAT() is a date-time function that returns a date as a string using the given format.

A NULL is returned if any argument is NULL.

The format string can contain any arbitrary text with the following formatting characters being replaced by date and time information:

Option

Description

%a

Abbreviated weekday name in the current locale

%b

Abbreviated month name in the current locale

%c

Month number in 1 or 2 digits

%D

Day number with English suffix "st", "nd", "rd", or "th"

%d

Day number in 2 digits

%e

Day number in 1 or 2 digits

%f

Microseconds (6 digits)

%H

Hour in 2 digits (00-23)

%h

Hour in 2 digits (01-12)

%I

Hour in 2 digits (01-12)

%i

Minute in 2 digits

%j

Numeric day of the year in 3 digits (001-366)

%k

Hour in 1 to 2 digits (0-23)

%l

Hour in 1 to 2 digits (1-12)

%M

Full month name in the current locale

%m

Month number in 2 digits

%p

AM or PM according to the current locale

%r

An alias for %I:%i:%S %p

%S

Seconds in 2 digits

%s

Seconds in 2 digits

%T

An alias for "%H:%i:%S"

%U

Week number (00-53) starting on Sunday

%u

Week number (00-53) starting on Monday

%V

Week number (01-53) starting on Sunday

%v

Week number (01-53) starting on Monday

%W

Full weekday name in current locale

%w

Day of the week (Sunday is 0)

%X

Year with 4 digits according to %V

%x

Year with 4 digits according to %v

%Y

Year with 4 digits

%y

Year with 2 digits

%%

A literal % character

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

SELECT DATE_FORMAT('2020-01-01 01:23:00', '%W %D %M %Y');
+---------------------------------------------------+
| DATE_FORMAT('2020-01-01 01:23:00', '%W %D %M %Y') |
+---------------------------------------------------+
| Wednesday 1st January 2020                        |
+---------------------------------------------------+
SELECT DATE_FORMAT('2020-01-01 01:23:00', '%H:%i:%s')
+------------------------------------------------+
| DATE_FORMAT('2020-01-01 01:23:00', '%H:%i:%s') |
+------------------------------------------------+
| 01:23:00                                       |
+------------------------------------------------+

ERROR HANDLING

FEATURE INTERACTION

RESPONSES

DIAGNOSIS

ISO 9075:2016

CHANGE HISTORY

Release Series

History

23.09

  • Present starting in MariaDB Xpand 23.09.1.

6.1

  • Present starting in MariaDB Xpand 6.1.0.

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.1

  • Present starting in MariaDB Xpand 6.1.0.

EXTERNAL REFERENCES