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

Matthew Dresser picture Matthew Dresser · Feb 11, 2009 · Viewed 138.3k times · Source

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 what's the best way to do this without storing more info than I actually need?

Answer

BigJump picture BigJump · Feb 11, 2009

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.