开发者

Store Duration in MySQL

What's the best method of storing the duration of an activity in a MySQL Table if there are 3 possibilities:

Activity lasts the full day Activity lasts only half a day User specifies the length in Hours:Minutes

The UI has a combobox with (Full Day/Half Day/Manual -> here a hour:minute selector shows up).

I am thinking of storing the duration in minutes in the database. And replace a Full Day with 480 minutes, half day with 240 minutes.

But I do not like the solution too much, cause in the frontend I need to check the duration and e.g if it is 480 set the combobox to Full Day.

What about an additional Field Type: 0 开发者_如何学编程- Full Day 1 - Half Day 2 - Manual

Wondering what the better/cleaner solution would be, or if there is a 3rd, better solution.

Thanks, martin


Using the minutes is a better solution, even if you have to line them up on the front-end.

It's cleaner from a storage perspective (one column rather than being redirected to the second column for manual settings) and allows more flexibility if the requirements change later (e.g. 1/4 day, 2 days).


I would implement using one column storing the minutes (or even seconds) of the time period.

An alternative display method you may want to consider is to allow the user to specify any time period they want using the d, h and m suffixes. eg.

'1d 4h 2m'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜