EXTRACT( )

This MySQL function extracts date or time information from a date or a datetime expression in the format type requested.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

EXTRACT(type FROM expression)

Explanation

This function extracts date or time information from a date or a datetime expression in the format type requested. The acceptable types are the same as the intervals for DATE_ADD( ). See table under that function for a list of intervals permitted.

Examples

SELECT NOW( ) AS 'Time Now', 
EXTRACT(HOUR_MINUTE FROM NOW( )) AS "Now in 'hhmm' format";

+---------------------+----------------------+
| Time Now            | Now in 'hhmm' format |
+---------------------+----------------------+
| 2008-03-14 20:36:04 |                 2036 | 
+---------------------+----------------------+