bcarl314
01-20-2005, 06:23 PM
At first glance, this may seem like a no brainer, but before you vote, please read this.
A few months back I had the fortune of working with a client that stored all his dates in a database as an int type, instead of a date type. All the data was a unix time (epoch time) so it actually worked quite will if you set up a few date() and mktime() calls in PHP. But I just thought it was a noob mistake, dealt with it, then moved on.
Now, I'm working on migrating an application I created using php and MS SQL server to a proper AMP environment (Apache, PHP and mySQL). Of course, my major problems lay around the DATEDIFF functions in SQL Server, and converting those queries and other queries using SQL SERVER only date functions to valid mysql date queries, then it hit me. If I had done all this with epoch time, this would have been a very simple migration.
So, what do you think? When storing dates in a database, do you use date or datetime types or int type with epoch time and handle the comparisons in your code?
I'd be interested to hear your responses.
A few months back I had the fortune of working with a client that stored all his dates in a database as an int type, instead of a date type. All the data was a unix time (epoch time) so it actually worked quite will if you set up a few date() and mktime() calls in PHP. But I just thought it was a noob mistake, dealt with it, then moved on.
Now, I'm working on migrating an application I created using php and MS SQL server to a proper AMP environment (Apache, PHP and mySQL). Of course, my major problems lay around the DATEDIFF functions in SQL Server, and converting those queries and other queries using SQL SERVER only date functions to valid mysql date queries, then it hit me. If I had done all this with epoch time, this would have been a very simple migration.
So, what do you think? When storing dates in a database, do you use date or datetime types or int type with epoch time and handle the comparisons in your code?
I'd be interested to hear your responses.