Storing date and time as epoch vs native datetime format in the database
For most of my tasks I find it much easier to work with date and time in th开发者_如何学JAVAe epoch format:
This list can go on, but for me in order to keep my code portable that's enough to ditch database's native datetime format and store date and time as integer. What do you guys think?
You should be able to solve the time zone issue by using UTC datetimes. I know C has a function for converting epoch times to UTC. I couldn't find one to go the other way, which confuses me.
I think I'm so use to proper Model objects and methods in MVC these dates and times functionality becomes trivial. I depend on the date & time library to the calculations. There's very few times where I have to write my own and and actually those times I overlooked the fact that the functionality was in the library already. If you are using PHP grab the date and time library from the Zend Framework. Once you have developed your model reuse it. Then you don't care how the date and time is stored in the DB.
The primary reason for using the database's DATETIME
type is that the POSIX time_t
has a very limited range; you cant store dates beyond the infamous Y2038, or before something around 1904. Since many databases need to store historical or future dates, there is a full range and usually portable DATETIME
; if in fact POSIX epoch times are more useful to you then go ahead and use them.
精彩评论