问题
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"?
回答1:
First, take a look here: http://dev.mysql.com/doc/refman/5.0/en/time.html
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'.
So, if you wanna insert a song with duration = 05:55, just write this:
insert into songs (duration) values('0555');
来源:https://stackoverflow.com/questions/10067939/how-to-store-time-duration-values-in-mysql-as-the-time-datatype