MySQL date_format: To get date in different styles.

My SQL has a special function that allows the developer to format the date in any way they wish by specifying a sequence of format strings. A string is composed of the percentage symbol ‘%‘ followed by a letter that signifies how you wish to display part of the date. These are some of the more common strings to use:

StringDisplaysExample
%dThe numeric day of the month01….10….17….24 etc
%DThe day of the month with a suffix1st, 2nd, 3rd…. etc
%mThe numeric month01….04….08….11 etc
%MThe Month nameJanuary….April….August etc
%bThe Abbreviated Month NameJan….Apr….Aug….Nov etc
%yTwo digit year98, 99, 00, 01, 02, 03 etc
%YFour digit year1998, 2000, 2002, 2003 etc
%WWeekday nameMonday…. Wednesday….Friday etc
%aAbbreviated Weekday nameMon….Wed….Fri etc
%HHour (24 hour clock)07….11….16….23 etc
%hHour (12 hour clock)07….11….04….11 etc
%pAM or PMAM….PM
%iMinutes01….16….36….49 etc
%sSeconds01….16….36….49 etc

You can use it in your mysql queries like this:

Comments are closed.