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.
Contact Us