如何在MySQL中将持续时间值存储为TIME数据类型?

编程入门 行业动态 更新时间:2024-10-25 07:33:58
本文介绍了如何在MySQL中将持续时间值存储为TIME数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要以分钟/秒为单位存储歌曲持续时间,我需要使用TIME,但是在编写INSERT语句时如何指代某个持续时间?我在表中的数据类型已经是TIME,我应该STR_TO_DATE字符串值"4:29"吗?

I need to store song durations in minutes/seconds, I need to use TIME, but how would I refer to a certain duration when I am writing an INSERT statement? My datatype in the table is already TIME, should I just STR_TO_DATE the string value of "4:29"?

推荐答案

首先,在这里看看: dev.mysql/doc/refman/5.0/en/time.html

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

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

因此,如果您想插入持续时间= 05:55的歌曲,只需编写以下内容:

So, if you wanna insert a song with duration = 05:55, just write this:

insert into songs (duration) values('0555');

更多推荐

如何在MySQL中将持续时间值存储为TIME数据类型?

本文发布于:2023-10-30 22:54:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544243.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   数据类型   持续时间   如何在   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!