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

前端 未结 15 2114
面向向阳花
面向向阳花 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:39

    IMHO what the best solution is depends to some extent on how you store time in the rest of the database (and the rest of your application)

    Personally I have worked with SQLite and try to always use unix timestamps for storing absolute time, so when dealing with the time of day (like you ask for) I do what Glen Solsberry writes in his answer and store the number of seconds since midnight

    When taking this general approach people (including me!) reading the code are less confused if I use the same standard everywhere

提交回复
热议问题