MySQL DATE_FORMAT: Usage & Examples

The DATE_FORMAT() function in MySQL is used to format date and time values. Its syntax is as follows:

DATE_FORMAT(date, format)

In this case, date refers to the date or time value that needs to be formatted, and format is the specified format string for the date or time format.

For example, to format a date field ‘2022-08-15′ as ’15/08/2022’, you can use the following query:

SELECT DATE_FORMAT('2022-08-15', '%d/%m/%Y');

The output is ’15/08/2022′. In the format string, %d represents the date (with leading zeros), %m represents the month (with leading zeros), and %Y represents the four-digit year. More formatting options can be found in the MySQL official documentation.

bannerAds