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

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

    Try smalldatetime. It may not give you what you want but it will help you in your future needs in date/time manipulations.

    0 讨论(0)
  • 2020-11-29 19:39

    Just store a regular datetime and ignore everything else. Why spend extra time writing code that loads an int, manipulates it, and converts it into a datetime, when you could just load a datetime?

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题