MySQL DATE_FORMAT() Function

Let’s look at some examples of the DATE_FORMAT() function in MySQL.

Example 1

Getting a formatted year as “2020” from the specified date “2020-11-23”.

SELECT DATE_FORMAT("2020-11-23", "%Y");

Output :

2020

Example 2

Getting a formatted month name as “November” from the specified date “2020-11-23”.

SELECT DATE_FORMAT("2020-11-23", "%M");

Output :

November

Example 3

Getting a day of the month as a numeric value as “23rd” from the specified date “2020-11-23”.

SELECT DATE_FORMAT("2020-11-23", "%D");

Output :

23rd

Example-4 :

Getting month day and year as “November 23 2020” from the specified date “2020-11-23”.

SELECT DATE_FORMAT("2020-11-23", "%M %d %Y");

Output :

November 23 2020

MySQL DATE_FORMAT() Function

MySQL DATE_FORMAT() function formats a specified date to a given format value.

Similar Reads

DATE_FORMAT() Function in MySQL

The DATE_FORMAT() function in MySQL formats a specified date or datetime according to the given format....

Syntax

MySQL DATE_FORMAT function Syntax is:...

MySQL DATE_FORMAT() Function Format Specifiers

This list of formats used in this function are listed below...

MySQL DATE_FORMAT() Function

Let’s look at some examples of the DATE_FORMAT() function in MySQL....

Important Points About MySQL DATE_FORMAT() Function

The MySQL DATE_FORMAT() function is used to format a date value based on a specific format. The DATE_FORMAT() function returns a string whose character set and collation depend on the settings of the client’s connection2. It will return NULL if any of the arguments are NULL. The DATE_FORMAT() function is supported in MySQL from version 4.01....

Contact Us