Best way to store time (hh:mm) in a database

前端 未结 15 2154
面向向阳花
面向向阳花 2020-11-29 18:58

I want to store times in a database table but only need to store the hours and minutes. I know I could just use DATETIME and ignore the other components of the date, but wha

15条回答
  •  半阙折子戏
    2020-11-29 19:19

    You could store it as an integer of the number of minutes past midnight:

    eg.

    0 = 00:00 
    60 = 01:00
    252 = 04:12
    

    You would however need to write some code to reconstitute the time, but that shouldn't be tricky.

提交回复
热议问题