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
Click here to design a Stunning Flash Website for Free
Wix is a revolutionary web design tool that provides anyone with the possibility to create professional and beautiful websites for free.
With e-commerce features, search engine visibility and many more professional tools, Wix is the ultimate solution for creating a spectacular site while saving tons of money.
|