MySQL DATE_FORMAT() Function Guide

The DATE_FORMAT() function in MySQL is used to output the value of a date or time field in a specific format. Its syntax is as follows:

DATE_FORMAT(date, format)

date is the value of a date or time field, while format is the format string used to specify the output format. There are many different format strings available to define various date and time formats, such as:

  1. %Y: year
  2. %m: month
  3. %d: Date
  4. %H: hours (in 24-hour format)
  5. %i: minutes
  6. %s: seconds

For example, to output the value of a date field in the “year-month-day” format, you can use the following statement:

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

This will convert the value of the date field to the format “YYYY-MM-DD”. Different format strings can be selected as needed to output different date or time formats.

bannerAds