Is it better to use 0 or NULL as the default for MySQL INT fields that store dates?

I need to live with INTs in our date / time records in MySQL, so I'm trying to figure out if it's better to use 0 or NULL as the default for these fields. We migrate and the data comes in as 0000-00-00 00:00:00, Unix timestamp, 0, NULL, false, etc, so I convert everything via PHP strtotime () and date () functions, but getting strange results when pasting.

I may end up with something useful in PHP, but I'm not sure after what is better to use as the default in MySQL.

+3


source to share


3 answers


0

- value. NULL

- lack of meaning.



Use NULL

.

+7


source


If you want to express lack of meaning, you must use Null

. 0 in the time epoch equals midnight on January 1, 1970. Therefore, based on the description of your situation, I would suggest using Null

.



http://www.epochconverter.com/

+1


source


I found that using NULL prevents dates or int from being "less than this" because MySQL does not compare ints and nulls in this context. When I set them to 0 by default, they came up with a selection and that was what we wanted. I'm not sure what complications this will cause in the future (we may have to find an alternative solution), but right now it is getting the data we need.

+1


source







All Articles