Supplemental Examples of MySQL Date Functions

This section lists the syntax and examples of MySQL date functions. These functions will be used in the Workshop. Note similarities and differences to ANSI syntax as previously shown in this chapter. MySQL date functions are listed in addition to ANSI SQL functions because date functions tend to differ between SQL implementations.

DATE_FORMAT

DATE_FORMAT(date,format) formats the date value according to the format string. The following specifiers can be used in the format string:

%MMonth name (January..December)
%WWeekday name (Sunday..Saturday)
%DDay of the month with English suffix (1st, 2nd, 3rd, etc.)
%YYear, numeric, 4 digits
%yYear, numeric, 2 digits
%XYear for the week where Sunday is the first day ...

Get Sams Teach Yourself SQL in 21 Days, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.