Open In App

DATE_FORMAT() Function in MariaDB

DATE_FORMAT() Function :
In MariaDB, the DATE_FORMAT() function uses two parameters – a date as specified by a format mask. In this function, the first parameter will be a date and the second parameter will be the mask. This function will return the date in the given mask. This function will convert the date with the masking format.

Syntax :



DATE_FORMAT(date, format_mask)

Parameters : Required.

Returns : The converted date as per the masking format.



Format :

Example-1 :

SELECT DATE_FORMAT('2020-04-09', '%M %d, %Y');

Output –

'April 09, 2020'

Example-2 :

SELECT DATE_FORMAT('2020-10-18', '%W');

Output –

'Sunday'

Example-3 :

SELECT DATE_FORMAT('2020-10-20', '%M %e %Y');

Output –

'October 20 2020'

Example-4 :

SELECT DATE_FORMAT('2020-10-19', '%W, %M %e, %Y');

Output –

'Monday, October 19, 2020'

Example-5 :

SELECT DATE_FORMAT('2014-05-17 08:44:21.000001', '%h');

Output –

8

Example-6 :

SELECT DATE_FORMAT('2019-08-11 10:44:21', '%s');

Output –

44

Example-7 :

SELECT DATE_FORMAT('2012-06-15 11:23:16', '%t');

Output –

11:23:16

Example-8 :

SELECT DATE_FORMAT('2019-03-13', '%M');

Output –

March

Example-9 :

SELECT DATE_FORMAT('2020-10-23', '%W');

Output –

Friday

Example-10 :

SELECT DATE_FORMAT('2019-05-13', '%Y');

Output –

'2019'
Article Tags :
SQL