MySQL Date Format: How to Format Dates

In MySQL, you can utilize the DATE_FORMAT() function to format dates.

The grammar is as follows:

DATE_FORMAT(date, format)

In this case, the “date” represents the date that needs to be formatted, and the “format” represents the display format of the date. The rules for formatting the date are as follows:

  1. %Y: A four-digit year
  2. %y: two-digit year
  3. %m represents the month (01-12).
  4. %c: Month (1-12)
  5. %d: Date (01-31)
  6. %H: Hours (00-23)
  7. %H: Hour (01-12)
  8. %i: minutes (00-59)
  9. %s: seconds (00-59)
  10. %W: Full name of the day of the week (Sunday-Saturday)
  11. %w: Weekday number (0-6, 0 represents Sunday)
  12. %M: Full month names (January-December)
  13. Month abbreviation (Jan-Dec)
  14. Abbreviation for days of the week (Sun-Sat)

For example, if you want to format the date as YYYY-MM-DD, you can use the following statement:

SELECT DATE_FORMAT(date, '%Y-%m-%d') FROM table_name;
bannerAds