MySQL DATE_FORMAT() Function

MySQL | DATE_FORMAT() Function: Learn about the DATE_FORMAT() function, how it works, its usages, syntax, and examples.
Submitted by Apurva Mathur, on October 11, 2022

DATE_FORMAT() Function

The DATE_FORMAT() function is used to format the given date value according to the given format, if any of the arguments is NULL, the function returns NULL.

DATE_FORMAT() Syntax

SELECT DATE_FORMAT(date, format);

DATE_FORMAT() Parameter(s)

This function requires two parameters:

  • date: firstly you have to provide the date on which you want to format.
  • format: Format is the arrangement you want your date to be in.

Let us the all the formats with the example,

MySQL DATE_FORMAT() Function Examples

  • %a: This is a abbreviation which we can use if we want to know the weekday name i.e. Sunday to Saturday.
    MySQL DATE_FORMAT() Example 1
  • %b: This is a abbreviation which we can use if we want to know the month name i.e. January to December.
    MySQL DATE_FORMAT() Example 2
  • %c: This is a abbreviation which we can use if we want to know the month name numerically i.e. 1 to 12 (1=Jan,2=Feb. etc)
    MySQL DATE_FORMAT() Example 3
  • %D: This will give you the month number with proper suffix.
    MySQL DATE_FORMAT() Example 4
  • %d: This will give you the month number without any suffix.
    MySQL DATE_FORMAT() Example 5
  • %e: This will give you the month number without any suffix.
    MySQL DATE_FORMAT() Example 6
  • %f: This will give you the detail about the microseconds (000000 to 999999).
    MySQL DATE_FORMAT() Example 7
  • %H: This will give the detail about hours in 12 hours format.
    MySQL DATE_FORMAT() Example 9
  • %h: This will give you the result about hours in 24 hours format.
    MySQL DATE_FORMAT() Example 8
  • %I: This will give the detail about hours in 12 hours format.
    MySQL DATE_FORMAT() Example 10
  • %i: This will give the detail about minutes (00 to 59).
    MySQL DATE_FORMAT() Example 11
  • %j: This will tell you the day of the year (001 to 366).
    MySQL DATE_FORMAT() Example 12
  • %k: This will give you the result about hours in 24 hours format.
    MySQL DATE_FORMAT() Example 13
  • %M: This will give you the full month name.
    MySQL DATE_FORMAT() Example 14
  • %m: This will give you the month name as a numeric value.
    MySQL DATE_FORMAT() Example 15
  • %p: This will tell you the whether it's a day or night i.e. AM OR PM.
    MySQL DATE_FORMAT() Example 16
  • %r: This will give you the time in 12 hour AM or PM format (hh:mm:ss AM/PM).
    MySQL DATE_FORMAT() Example 17
  • %S: This will give you the detail about the seconds (00 to 59).
    MySQL DATE_FORMAT() Example 18
  • %s: This will give you the detail about the seconds (00 to 59).
    MySQL DATE_FORMAT() Example 19
  • %T: This will give you the time in 24 hour format (hh:mm:ss).
    MySQL DATE_FORMAT() Example 20
  • %U: Week where Sunday is the first day of the week (00 to 53).
    MySQL DATE_FORMAT() Example 21
  • %u: It will tell you the Week where Monday is the first day of the week (00 to 53).
    MySQL DATE_FORMAT() Example 22
  • %V: It will tell you the Week where Sunday is the first day of the week (01 to 53). Used with %X.
    MySQL DATE_FORMAT() Example 23
  • %v: Week where Monday is the first day of the week (01 to 53). Used with %x.
    MySQL DATE_FORMAT() Example 24
  • %W: Weekday name in full (Sunday to Saturday).
    MySQL DATE_FORMAT() Example 25
  • %w: Day of the week where Sunday=0 and Saturday=6.
    MySQL DATE_FORMAT() Example 26
  • %X: Year for the week where Sunday is the first day of the week. Used with %V.
    MySQL DATE_FORMAT() Example 27
  • %x: Year for the week where Monday is the first day of the week. Used with %v.
    MySQL DATE_FORMAT() Example 28
  • %Y: It tells you the year as a numeric, 4-digit value.
    MySQL DATE_FORMAT() Example 29
  • %y: It tells you the year as a numeric, 2-digit value.
    MySQL DATE_FORMAT() Example 30



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.