Ray
Ray

Reputation: 685

MySQL How to do Operations on Time like 30:47 (30 minutes and 47 seconds)

I'm using MySQL and I currently have a VARCHAR column which stores times (in minutes and seconds) like "30:47" and "00:25" (25 seconds). How can I make it so that I can do operations like SUM() and AVG() on this column and get the result back.

So if I did AVG() on "00:35" and "00:45" I would get "00:40". Would I have to convert them to a decimal format first, then do the operation and then convert it back? Or is there a column type that would support these operations?

Upvotes: 2

Views: 245

Answers (1)

Corbin
Corbin

Reputation: 33447

Just use a TIME column. It will support most operations intuitively.

Upvotes: 5

Related Questions