Extraction Functions : Introduction « Date Time Functions « MySQL Tutorial






Extraction functions extract specific information about a date (year, month, day etc).

These include:

FunctionDisplaysExample
DAYOFMONTH(date)The numeric day of the month01, 10, 17, 24 etc
DAYNAME(date)The Name of the dayMonday, Wednesday, Friday etc
MONTH(date)The numeric month01, 04, 08, 11 etc
MONTHNAME(date)The Month nameJanuary, April, August etc
YEAR(date)Four digit year1998, 2000, 2002, 2003 etc
HOUR(time)Hour (24 hour clock)07, 11, 16, 23 etc
MINUTE(time)Minutes01, 16, 36, 49 etc
SECOND(time)Seconds01, 16, 36, 49 etc
DAYOFYEAR(date)Numeric day of the year1, 366


mysql>
mysql> SELECT DAYNAME('1989-07-20');
+-----------------------+
| DAYNAME('1989-07-20') |
+-----------------------+
| Thursday              |
+-----------------------+
1 row in set (0.00 sec)

mysql>








14.1.Introduction
14.1.1.Date and Time Functions
14.1.2.Extraction Functions
14.1.3.Changing Date Values
14.1.4.Getting Day Information
14.1.5.Getting Names for Months and Days
14.1.6.Extracting Years, Quarters, Months, and Weeks
14.1.7.Current Date and Time
14.1.8.Days Since 1 A.D.
14.1.9.Seconds Since the Beginning of the Day