Results 1 to 7 of 7
Jul 24, 2013, 09:41 #1
- Join Date
- May 2006
- 2 Post(s)
- 0 Thread(s)
PHP and MySQL date: why not use INT(14)?
I've been looking at the MySQL date/time fields and also the option of just storing a UNIX timestamp. What I've always done, however, is store as date and time as a 14 digit int (YYYMMDDHHMMSS). It's easy to order by and is human readable.
From what I can tell the advantage of using a UNIX timestamp is that it's primed for use with PHP's date function and MySQL has the function to query themóbut really formatting YYYMMDDHHMMSS for whatever use you want is pretty easy. Am I missing something other than the int is smaller?
I can see the advantage of using MySQL's datetime if you're going to be doing more complex date-based queries and need to make use of some of MySQL's date functions. But, aren't they stored as strings and therefore slower than ints?
I'm not sure whether to carry on as I am or start to use either of the above. I quite like the UNIX timestamp idea as the raw date being readable in the database is not really an argument to keep it that way. And is it safe to say by 2038 UNIX timestamp will still be working?