EXTRACT(type FROM date)

Description: Extracts the given type (YEAR, HOUR, and so on) from date (a date, or date and time). The formatting principles are the same as for ADDDATE(), and possible values for type are as shown previously in Table C.1.

Examples:

  • EXTRACT(YEAR_MONTH FROM '2002-06-01') returns 200206.

  • EXTRACT(HOUR_MINUTE FROM '2002-06-01 09:30:00') returns 930.

See also: ADDDATE()

Get Sams Teach Yourself MySQL in 21 Days, Second 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.