Back to LinkedIn posts

LinkedIn post 312

I've found this article interesting: it advocates for storing timestamps instead of...

I've found this article interesting: it advocates for storing timestamps instead of boolean flags in databases.

The reason is that storing timestamps is almost always more beneficial in the long run because it provides additional context of when an event occurred without significant downsides in storage or complexity. That is a sort of future-proofing your data model. ๐Ÿ’ก

To be clearer, we're not talking about some status that would toggled back and forth.

๐Ÿ‘‰๐Ÿผ So instead of a mere true/false state, the data would provides valuable context about when the state was set to true (assuming the default is false). NULL timestamp would be functionally equivalent to false and a non-NULL timestamp equivalent to true.

๐Ÿ™๐Ÿผ Thanks for this great insight goes to Jerod Santo ! ๐Ÿ™๐Ÿผ

Another advantage of having timestamps is that it facilitates scheduling an action in response to the change. It can also facilitate when rolling back the state to prior to a certain date/time.

LINK:
You might as well timestamp it
future-you will be glad you stored a timestamp instead of that boolean
๐Ÿ”—