MySQL 5.7-11.2.3 The TIME Type

MySQL中的TIME类型用于存储时间值,范围从'-838:59:59'到'838:59:59',可精确到微秒。它可以表示一天内的时刻,也可以表示时间间隔。时间值可以有多种格式,包括带有或不带冒号的缩写,解析时需注意其含义。超出范围的值会被裁剪,而无效值则转换为'00:00:00'。在严格SQL模式下,无效时间值会导致错误。
摘要由CSDN通过智能技术生成

MySQL retrieves and displays TIME values in 'hh:mm:ss' format (or 'hhh:mm:ss' format for large hours values). TIME values may range from '-838:59:59' to '838:59:59'. The hours part may be so large because the TIME type can be used not only to represent a time of day (which must be less than 24 hours), but also elapsed time or a time interval between two events (which may be much greater than 24 hours, or even negative).

MySQL以“hh:mm:ss”格式(或者“hhh:mm:ss”格式)检索并显示TIME值。TIME的取值范围为“-838:59:59”到“838:59:59”。小时的部分可能是如此之大,因为可以使用时间类型不仅代表一个时间(必须小于24小时),而且运行时间或两个事件之间的时间间隔(这可能是远远大于24小时,甚至负)。

MySQL recognizes TIME values in several formats, some of which can include a trailing fractional seconds part in up to microseconds (6 digits) precision. See Section 9.1.3, “Date and Time Literals”. For information about fractional seconds support in MySQL, see Section 11.2.7, “Fractional Seconds in Time Values”. In particular, any fractional part in a value inserted into a TIME column is stored rather than discarded. With the fractional part included, the range for TIME values is '-838:59:59.000000' to '838:59:59.000000'.

MySQL可以识别几种格式的TIME值,其中一些格式可以包含一个尾随的小数秒,精度可达微秒(6位)。参见第9.1.3节“日期和时间文字”。关于MySQL中对分数秒的支持,请参见11.2.7节“时间值中的分数秒”。特别是,插入到TIME列的值中的任何小数部分都将被存储,而不是丢弃。如果包含小数部分,TIME的取值范围是'-838:59:59 000000'到'838:59:59 000000'。

Be careful about assigning abbreviated values to a TIME column. MySQL interprets abbreviated TIME values with colons as time of the day. That is, '11:12' means '11:12:00', not '00:11:12'. MySQL interprets abbreviated values without colons using the assumption that the two rightmost digits represent seconds (that is, as elapsed time rather than as time of day). For example, you might think of '1112' and 1112 as meaning '11:12:00' (12 minutes after 11 o'clock), but MySQL interprets them as '00:11:12' (11 minutes, 12 seconds). Similarly, '12' and 12 are interpreted as '00:00:12'.

在给TIME列赋缩位值时要小心。MySQL将带有冒号的TIME值缩写为一天中的时间。也就是说,11:12的意思是11:12:00,而不是00:11:12。MySQL在解释没有冒号的缩写值时,假设最右边的两个数字表示秒(也就是说,表示经过的时间而不是一天中的时间)。例如,您可能认为'1112'和1112的意思是'11:12:00'(11点后的12分钟),但MySQL将它们解释为'00:11:12'(11分12秒)。类似地,'12'和12被解释为'00:00:12'。

The only delimiter recognized between a time part and a fractional seconds part is the decimal point.

在时间部分和小数秒部分之间识别的唯一分隔符是小数点。

By default, values that lie outside the TIME range but are otherwise valid are clipped to the closest endpoint of the range. For example, '-850:00:00' and '850:00:00' are converted to '-838:59:59' and '838:59:59'. Invalid TIME values are converted to '00:00:00'. Note that because '00:00:00' is itself a valid TIME value, there is no way to tell, from a value of '00:00:00' stored in a table, whether the original value was specified as '00:00:00' or whether it was invalid.

默认情况下,位于TIME范围之外但在其他方面有效的值将被裁剪到该范围中最近的端点。例如,'-850:00:00'和'850:00:00'会转换为'-838:59:59'和'838:59:59'。无效的TIME值将被转换为“00:00:00”。注意,由于'00:00:00'本身是一个有效的TIME值,因此无法从存储在表中的'00:00:00'值判断原始值是指定为'00:00:00'还是无效的。

For more restrictive treatment of invalid TIME values, enable strict SQL mode to cause errors to occur. See Section 5.1.10, “Server SQL Modes”.

要对无效的TIME值进行更严格的处理,请启用严格的SQL模式以导致错误发生。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值