要点

  1. mysql中有DATE, TIME, DATETIME, TIMESTAMP, YEAR5种时间类型

  2. 时间类型的零值0000-00-00 00:00:00

  3. mysql输出时间值时,默认为标准格式2006-01-02 15:04:05

  4. mysql读入时间值时(赋值, 比较等操作),会尝试转换各种值如整数20151020, "2015-10-20"等(详见)

常用函数

  1. 格式化时间值

    select date_format('2015-10-20 16:00:04', "%Y%m");
    

参考

  1. https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
  2. https://dev.mysql.com/doc/refman/5.5/en/date-and-time-types.html
  3. https://dev.mysql.com/doc/refman/5.5/en/date-and-time-literals.html
  4. https://dev.mysql.com/doc/refman/5.5/en/storage-requirements.html

留言

2015-10-20