在MySQL中格式化日期以返回MonthName,Year [英] Format date in MySQL to return MonthName, Year
本文介绍了在MySQL中格式化日期以返回MonthName,Year的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表中有需要按日期排序的行.很容易,使用date
数据类型存储它们,ORDER BY
日期等等.
I have rows in a table that I need to order by date. Easy enough, use the date
datatype to store them, ORDER BY
date blah blah.
但是,我试图获取这些行,并将日期轻松转换为MonthName, Year
However, I'm trying to get these rows, and easily convert the date to MonthName, Year
如果我将行的日期存储为2011-11-16
,我想提取该日期(使用PHP)并打印出来:
If I had stored a row's date as 2011-11-16
, I would want to extract this (using PHP) and print out:
November, 2011
推荐答案
尝试一下
SELECT DATE_FORMAT(`date`,'%M %Y') AS showdate FROM table
使用此站点 http://www.mysqlformatdate.com/来获取(mysql)日期格式你想要
Use this site http://www.mysqlformatdate.com/ to get the (mysql) date format you want
这篇关于在MySQL中格式化日期以返回MonthName,Year的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文