Mysql 日期时间类型

Mysql 日期时间类型

DATE, TIME, DATETIME, TIMESTAMP, YEAR
TIME, DATETIME, or TIMESTAMP 支持小数秒: type_name(fsp), fsp 是小数秒, 范围是 0 - 6

1. Date

范围 ‘1000-01-01’ to ‘9999-12-31’
允许使用 string 或者 number 分配给 date 列,如 ‘2021-09-26’, ‘20210926’, 20210926

2. DATETIME[(fsp)]

范围 ‘1000-01-01 00:00:00.000000’ to ‘9999-12-31 23:59:59.999999’
可以是 string 或者 number

3. TIMESTAMP[(fsp)]

范围 ‘1970-01-01 00:00:01.000000’ UTC to ‘2038-01-19 03:14:07.999999’ UTC
注意时区问题,在中国是从 ‘1970-01-01 08:00:01.000000’ 开始的

MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval.

mysql 存储时间戳是 utc 时间戳,展示是按照系统的时区来的

查看时区

select @@time_zone, @@system_time_zone;

4. TIME[(fsp)]

范围:’-838:59:59.000000’ to ‘838:59:59.000000’

表示 两个时间的差值时,不受24小时的限制
超出范围的,变成最近的时间点,, ‘-850:00:00’ and ‘850:00:00’ are converted to ‘-838:59:59’ and ‘838:59:59’

可以是 string 或者 number

  • 有冒号的缩写,从左到右识别。 如 12:11 被识别为 12:11:00
  • 没有冒号的缩写,从右到做识别。如 12 被识别为 00:00:12

5. YEAR[(4)]

范围 1901 to 2155, or 0000.

注意:

MySQL permits a “relaxed” format for values specified as strings, in which any punctuation character may be used as the delimiter between date parts or time parts.
MySQL 允许指定为字符串的值的“宽松”格式,其中任何标点字符都可以用作日期部分或时间部分之间的分隔符。
如插入 10:12:11 到 date 列时,会被转化为 2010-12-11

The server requires that month and day values be valid, and not merely in the range 1 to 12 and 1 to 31, respectively.
服务器要求月和日值是有效的,而不仅仅是分别在 1 到 12 和 1 到 31 的范围内。

Dates containing 2-digit year values are ambiguous because the century is unknown. MySQL interprets 2-digit year values using these rules:
Year values in the range 00-69 become 2000-2069.
Year values in the range 70-99 become 1970-1999.
两位数字的年份,00-69 被理解为 2000-2069,70-99 被理解为 1970-1999

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值