Invalid date storage in database

I keep some records in the database. The record has a "last visit" field, which is a timestamp. If the record has not yet been visited, the timestamp is invalid. I am currently storing a future date, for example. '2101-01-01 00:00:00' in the 'last visited' field to indicate an invalid date.

Is there a better way to indicate the date is "invalid". What is the recommended β€œbest practice” for this?

I am using MySQL, but ideally the recommendation should be db agnostic

+5
source share
4 answers

Save the NULL value. MySQL timestamps are pretty confusing, so you might need to change the table layout to prompt it to let you put NULL there; Instead, I use DATETIME, which is a little less strange than TIMESTAMPs in MySQL.

+6
source

The appropriate method of storing something that does not matter is simply the absence of value. That is, zero. Keeping everything else and considering it as a magical meaning is often problematic. There are times when a magic value may be a valid value, and now you have no way to distinguish between the two.

+3
source

null.

, .

+1

, NULL ?

0

All Articles