Is it possible to fetch only the month part from a sql date entry?
like the date is stored like '2011-01-06'
. if i want to fetch only the '01'
portion how can I do that?
thanxx in advance.
您可以使用DATE_FORMAT
来执行此操作,如下所示:
SELECT DATE_FORMAT(DateField, '%m') FROM table
you can do it in mysql
like :
select DATE(date_field) from mytable
from manual :
MONTH(date)
Returns the month for date, in the range 1 to 12 for January to December, or 0 for dates such as '0000-00-00' or '2008-00-00' that have a zero month part.
mysql> SELECT MONTH('2008-02-03');
-> 2
在mysql查询中,您可以这样做:
MONTH(date_field)
mysql> SELECT MONTH ('2008-02-03');
Result : 2
You can use the MONTH
function of MySQL:
SELECT MONTH('2011-01-06');
Result:
1
To get month name instead, you can use MONTHNAME
like this:
SELECT MONTHNAME('2011-01-06');
Result:
January
你可能想试试
select substring(`mydate_field`,6,2) from `table_name`;
In ANSI-SQL you can use EXTRACT:
SELECT
EXTRACT('month' FROM fieldname)
FROM
tablename;
This works in many databases, MySQL as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.