As we prepare to “fall back” this weekend in the US I’ve been thinking about writing code that deals with dates and times. This is easy to get wrong and is a common cause of bugs.
The first issue is how to write dates. For example, if I write 11/03/2021 that means November Third in the US, but in other countries it might be March Eleventh. Oops.
With that in mind, I always use ISO 8601 format for dates: 2021-11-03. To me this just makes sense. The year is the biggest so it comes first, followed by the month and day. In a Rails console you can try something like this: