MySQL EXTRACT() Function
MySQL Date Functions
Definition and Usage
The EXTRACT() function is used to return a single part of a date/time, such
as year, month, day, hour, minute, etc.
Syntax
Where date is a valid date expression and unit can be one of the following:
Unit Value |
MICROSECOND |
SECOND |
MINUTE |
HOUR |
DAY |
WEEK |
MONTH |
QUARTER |
YEAR |
SECOND_MICROSECOND |
MINUTE_MICROSECOND |
MINUTE_SECOND |
HOUR_MICROSECOND |
HOUR_SECOND |
HOUR_MINUTE |
DAY_MICROSECOND |
DAY_SECOND |
DAY_MINUTE |
DAY_HOUR |
YEAR_MONTH |
Example
Assume we have the following "Orders" table:
OrderId |
ProductName |
OrderDate |
1 |
Jarlsberg Cheese |
2008-11-11 13:23:44.657 |
The following SELECT statement:
SELECT EXTRACT(YEAR FROM OrderDate) AS OrderYear,
EXTRACT(MONTH FROM OrderDate) AS OrderMonth,
EXTRACT(DAY FROM OrderDate) AS OrderDay,
FROM Orders
WHERE OrderId=1
|
will result in this:
OrderYear | OrderMonth |
OrderDay |
2008 | 11 | 11 |
MySQL Date Functions
|
|
|
See why there are 20,000+ Ektron integrations worldwide.
Request an INSTANT DEMO or download a FREE TRIAL today. |
|
|
|