Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have to live with an INT in our date/time records in MySQL, so I'm trying to figure out whether it's better to use 0 or NULL as the default for those fields. We're migrating, and data is coming in as 0000-00-00 00:00:00, a Unix timestamp, 0, NULL, false, etc, so I'm converting everything through the PHP strtotime() and date() functions, but getting weird results on insert.

Ultimately I can end up with something usable in PHP, but I'm not sure whether after the fact which is better to use as the default in MySQL.

like image 512
Davicus Avatar asked Dec 19 '25 01:12

Davicus


2 Answers

0 is a value. NULL is a lack of a value.

Use NULL.

like image 132
Kermit Avatar answered Dec 21 '25 15:12

Kermit


If you want to express the absence of a value, you should use Null. 0 in epoch time is equal to midnight on January 1, 1970. Therefore, based on the description of your situation I would suggest using Null.

http://www.epochconverter.com/

like image 26
Mike Avatar answered Dec 21 '25 14:12

Mike