I am storing some records in a database. A record has a 'last visited' field which is a timestamp. If a record has not been visited yet, the timestamp is invalid. I am currently storing a future date e.g. '2101-01-01 00:00:00' in the 'last visited' field, to denote an invalid date.
Is there a better way to indicate an 'invalid' date. What is the recommended 'best practise' for doing this?
I am using MySQL, but ideally, the recommendation should be db agnostic
Rule #1 - STORE DATETIMES IN UTC IN YOUR DATABASE, AND BACK END CODE. It is important that there is consistency across all your date-related data. When storing dates in the database, they should always be in UTC.
Check the content of the spreadsheet you are trying to upload. Dates in your spreadsheet may be formatted in ways other than mmm-yyyy, such as dd-mmm-yyyy. Right-click these dates and click Format. Under Number, set a format of mmm-yyyy.
A lot of users select the entire range and then go to Format Cell and then change the format of the Date. But it will not change anything as it is not a valid date format in Excel since dot separators are invalid. If it is not a date, then it's simple text to excel.
We recommend setting your Google Sheets cells as "date" format to ensure date range compatibility. If you're getting an invalid date format on your widget, please format your date column by selecting the column > Format > Number > Date.
Store a NULL value instead. MySQL timestamps are pretty screwed up, so you might need to change your table schema to encourage it to let you put a NULL in there; I use DATETIME instead, it's a little less weird than TIMESTAMPs in MySQL.
The appropriate method of storing something of no value is to simply provide no value. That is to say, a null. Storing anything else and treating it as a magical value is often problematic. There are times when the magical value can be a valid value, and now you have no method of distinguishing the two.
I would just leave the field null.
If they've never visited the record, it shouldn't have a timestamp at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With