`

mysql 日期格式化date_format详细使用

阅读更多
  • 日期转换函数的详细使用说明
  •  DATE_FORMAT(date,format)

    Formats the date value according to the format string.

    The following specifiers may be used in the format string. The “%” character is required before format specifier characters.

    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 (0th1st2nd3rd, …)
    %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; WEEK() mode 0
    %u Week (00..53), where Monday is the first day of the week; WEEK() mode 1
    %V Week (01..53), where Sunday is the first day of the week; WEEK() mode 2; used with %X
    %v Week (01..53), where Monday is the first day of the week; WEEK() mode 3; 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

    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'.

    The language used for day and month names and abbreviations is controlled by the value of the lc_time_namessystem variable (Section 10.7, “MySQL Server Locale Support”).

    For the %U%u%V, and %v specifiers, see the description of the WEEK() function for information about the mode values. The mode affects how week numbering occurs.

    DATE_FORMAT() returns a string with a character set and collation given by character_set_connection andcollation_connection so that it can return month and weekday names containing non-ASCII characters.

    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'
分享到:
评论

相关推荐

    MySql用DATE_FORMAT截取DateTime字段的日期值

    用 DATE_FORMAT 来格式化日期字段 SELECT DATE_FORMAT(crt_time,'%Y-%m-%d') FROM ad_n_advertise_t 您可能感兴趣的文章:MySQL中日期比较时遇到的编码问题解决办法PHP以及MYSQL日期比较方法mysql 获取当前日期函数...

    Mysql 日期时间 DATE_FORMAT(date,format)

    本文转自:http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_date-format DATE_FORMAT(date,format) Formats the date value according to the format string. The following ...

    详解mysql 获取当前日期及格式化

    MySQL 获取当前日期及日期格式 获取系统日期: NOW() ...根据format字符串格式化date值: %S, %s 两位数字形式的秒( 00,01, …, 59) %I, %i 两位数字形式的分( 00,01, …, 59) %H 两位数字形式的小时,24 小时

    动力节点MySQL数据库入门视频教程-073-date_format日期格式化

    动力节点的杜老师讲述的mysql教程,详细讲解了MySQL的相关知识,包括MySQL概述,MySQL应用环境,MySQL系统特性,MySQL初学基础,MySQL管理工具,如何安装MySQL及MySQL新特性,通过观看可掌握MySQL全套知识。

    MySQL IF、 Bewteen、 AS、 Date_Format、Left join on等关键字实例

    我们在写SQL时候,往往会需要格式化或多表联合查询,现在来一个实例看看这个问题 SELECT t.id, t.topic_title AS title, IF(sch.is_true='1','答案正确','答案错误') as answer, DATE_FORMAT(sch.create_time, '%Y-%...

    mysql From_unixtime及UNIX_TIMESTAMP及DATE_FORMAT日期函数

    mysql日期函数From_unixtime及UNIX_TIMESTAMP及DATE_FORMAT(后者只能格式化标准日期格式,时间戳的不行)

    mysql中格式化日期详解

    1. DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据。 DATE_FORMAT(date,format) format参数的格式有 %a 缩写星期名 %b 缩写月名 %c 月,数值 %D 带有英文前缀的月中的天 %d 月的天,数值(00-31)...

    thinkphp5.1框架实现格式化mysql时间戳为日期的方式小结

    本文实例讲述了thinkphp5.1框架实现格式化mysql时间戳为日期的方式。分享给大家供大家参考,具体如下: 方式一 使用mysql函数FROM_UNIXTIME(unix_timestamp,format)直接转换 select FROM_UNIXTIME(o.create_time,'...

    Python MySQL 日期时间格式化作为参数的操作

    1.我的MySQL中的start_time存储的是2018-03-21 10:55:32格式的时间,我需要按照YYYY-MM-DD格式来查询,我的MySQL中的sql是这样写的: SELECT * from mytable WHERE DATE_FORMAT(start_time,”%Y-%m-%d”)=’2018-03...

    mysql 获取当前日期函数及时间格式化参数详解

    MYSQL 获取当前日期及日期格式 ...根据format字符串格式化date值: %S, %s 两位数字形式的秒( 00,01, …, 59) %I, %i 两位数字形式的分( 00,01, …, 59) %H 两位数字形式的小时,24 小时(00,01, …, 23)

    详解MySQL日期 字符串 时间戳互转

    date_format(date, format) 函数,MySQL日期格式化函数date_format() unix_timestamp() 函数 str_to_date(str, format) 函数 from_unixtime(unix_timestamp, format) 函数,MySQL时间戳格式化函

    FROM_UNIXTIME 格式化MYSQL时间戳函数

    函数:FROM_UNIXTIME...根据format字符串格式化date值。下列修饰符可以被用在format字符串中: %M 月名字(January……December)%W 星期名字(Sunday……Saturday)%D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。)%

    format格式.xls

    总结的MySQL format格式化的格式('%Y-%m-%d %H:%i:%s'),可用于MySQL格式化函数(FROM_UNIXTIME(timestamp,format)、DATE_FORMAT(date, format)等。)

    关于mysql数据库格式化简单介绍

    可用DATE_FORMAT( ) 来格式化DATE 或DATETIME 值,以便得到所希望的格式。根据format字符串格式化date值: %S, %s 两位数字形式的秒( 00,01, . . ., 59) %i 两位数字形式的分( 00,01, . . ., 59) %H 两位数字...

    mysql的日期和时间函数

    mysql的日期和时间函数 这里是一个使用日期函数的例子。下面的查询选择所有 date_col 值在最后 30 天内的记录。 mysql> SELECT something FROM tbl_name WHERE TO_DAYS(NOW()) - TO_DAYS(date_col) ...

    几个实用的MySQL内置函数实用说明

    日期格式化函数: DATE_FORMAT:时间格式化为字符串; STR_TO_DATE:时间字符串转为为日期格式; 日期加减函数: DATE_SUB:日期做减法 DATE_ADD:日期做加法

    mysql unix准换时间格式查找指定日期数据代码

    代码如下: select * from table where DATE_FORMAT(FROM_UNIX...timestamp,format)是MySQL里的时间函数 ,unix_timestamp可以是字段名,也可以直接是Unix时间,format主要是将返回值格式化。 若format已经给出,则结果的

    php Mysql日期和时间函数集合

    根据format字符串格式化date值。下列修饰符可以被用在format字符串中: %M 月名字(January……December)  %W 星期名字(Sunday……Saturday)  %D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。)  %Y 年...

    MySQL常用命令

    MySQL常用命令 日期 / 时间函数 -- 当前日期时间 select now() select sysdate() select current_timestamp() -- 当前日期 select current_date()...-- 格式化时间 select date_format('yyyy-mm-dd hh:ii:ss', '%d

Global site tag (gtag.js) - Google Analytics