I\'m creating a schema in Mongoose, and I\'m trying to figure out the best way to store a field representing the time of day ie 3:30, it does not need to be a fully qualifie
I'd suggest storing it either as seconds since midnight (as a Number
) or as a padded numeric String
stored in 24 hour format.
For example, 3:30PM
:
55800
"1530"
(always must be 24 hour format with a leading numeric digit to have the same number of places, so 8:30AM
would be "0830"
Both can be sorted, indexed, queried by range. Both take approximately the same number of bytes. Since neither is very human friendly readable, you'd probably need to format them either way for display. It's really up to you which one would work better for your use.