设为首页 收藏本站
查看: 400|回复: 0

[经验分享] MySql Date_Format(data,format)

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-7-21 08:53:46 | 显示全部楼层 |阅读模式
DATE_FORMAT(date,format)
Formats the date value according to the format string.
The following specifiers may be used in the format string. As of MySQL 3.23, the “%” character is required before format specifier characters. In earlier versions of MySQL, “%” was optional.
Specifier        Description
%a        Abbreviated weekday name (Sun..Sat)
%b        Abbreviated month name (Jan..Dec)
%c        Month, numeric (0..12)
%D        Day of the month with English suffix (0th, 1st, 2nd, 3rd, …)
%d        Day of the month, numeric (00..31)
%e        Day of the month, numeric (0..31)
%f        Microseconds (000000..999999)
%H        Hour (00..23)
%h        Hour (01..12)
%I        Hour (01..12)
%i        Minutes, numeric (00..59)
%j        Day of year (001..366)
%k        Hour (0..23)
%l        Hour (1..12)
%M        Month name (January..December)
%m        Month, numeric (00..12)
%p        AM or PM
%r        Time, 12-hour (hh:mm:ss followed by AM or PM)
%S        Seconds (00..59)
%s        Seconds (00..59)
%T        Time, 24-hour (hh:mm:ss)
%U        Week (00..53), where Sunday is the first day of the week
%u        Week (00..53), where Monday is the first day of the week
%V        Week (01..53), where Sunday is the first day of the week; used with %X
%v        Week (01..53), where Monday is the first day of the week; used with %x
%W        Weekday name (Sunday..Saturday)
%w        Day of the week (0=Sunday..6=Saturday)
%X        Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V
%x        Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v
%Y        Year, numeric, four digits
%y        Year, numeric (two digits)
%%        A literal “%” character
%x        x, for any “x” not listed above
The %v, %V, %x, and %X format specifiers are available as of MySQL 3.23.8. %f is available as of MySQL 4.1.1.
Ranges for the month and day specifiers begin with zero due to the fact that MySQL permits the storing of incomplete dates such as '2014-00-00' (as of MySQL 3.23).
As of MySQL 4.1.21, the language used for day and month names and abbreviations is controlled by the value of the lc_time_names system variable (Section 9.8, “MySQL Server Locale Support”).
As of MySQL 4.1.23, DATE_FORMAT() returns a string with a character set and collation given by character_set_connection and collation_connection so that it can return month and weekday names containing non-ASCII characters. Before 4.1.23, the return value is a binary string.
mysql> SELECT DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y');
    -> 'Sunday October 2009'
mysql> SELECT DATE_FORMAT('2007-10-04 22:23:00', '%H:%i:%s');
    -> '22:23:00'
mysql> SELECT DATE_FORMAT('1900-10-04 22:23:00',
  ->         '%D %y %a %d %m %b %j');
    -> '4th 00 Thu 04 10 Oct 277'
mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00',
  ->         '%H %k %I %r %T %S %w');
    -> '22 22 10 10:23:00 PM 22:23:00 00 6'
mysql> SELECT DATE_FORMAT('1999-01-01', '%X %V');
    -> '1998 52'
mysql> SELECT DATE_FORMAT('2006-06-00', '%d');
    -> '00'


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-88894-1-1.html 上篇帖子: 源码安装mysql出现 No curses/termcap library found 错误 下篇帖子: 【Mysql5.5 XP系统下载】mysql XP系统安装图解
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表