As the senior dev it was my job to provide info as needed and subtly assess the new, potential rockstar code ninjas.
Anyway, this new guy says "I store all my dates in sql as text in iso format so I can easily sort them".
If he had said anything other than "in sql" it would be the correct answer.
"I store all dates in spreadsheets in ISO format"
"I prepend ISO dates to marketing campaign names so I can easily sort them in the horrible web frontends that doesn't have a sort by date option"
"I start all my blog entries with ISO dates..."
I mean, just... so close!
As in SQL, the application’s native date format (which is usually a number with appropriate format) would be the natural choice and a YYYY-MM-DD string would be a distant second. ISO (presumably, 8601) format is too broad, and admits of a mix of formats that are not simply sortable (quick, which is first 2021-W14-2 or 2021-04-07?).
If a date is going to be string prepended to something else, or if the spreadsheet is going to be exported to CSV, or parsed by some tool, then storing dates in YYYY-MM-DD can be a very justifiable thing to do in a spreadsheet.
Also Excel likes to format dates using the system locale, which is, well, stupid. So I have to enter YYYY-MM-DD as a custom format anyway, or change the locale on the column to China. (Or Cherokee, who apparently also properly format their dates!)
(Also Excel is smart enough if you set a column as YYYY-MM-DD custom format, it'll let you use all the date based pivot table stuff as expected)
Strong SQLite vibes... (SQLite doesn't have a date format, it has builtin functions that accept ISO format text or unix timestamps)
Among the option of storing (date field, millisecond field) and (date as iso8601 text field with millisecond without time zone) I chose the latter, and I can’t tell for sure but it was almost surely the better choice.
I saw no benefit in storing two copies. That’s recipe for problems - e.g. “update” code that doesn’t update both, or somehow updates them differently (which one is right?). You can probably have t-sql or some “check” constraint to enforce equivalence, but ... why?
For most practical uses, an ISO8601 textual representation is as good, though a little less space efficient.
No, it doesn’t, since all of the following are valid ISO 8601 representations of a date:
20210408 2021-04-07 2021-W14-1 2021W143 2021-097 2021098
(Now, consistently using any one of the ISO 8601 formats is sortable...)
I always recommend and use the specific ISO8601 format
YYYY-MM-DDThh:mm:ss.sssZ
(or drop the ".sss" if not needed), and be 100% consistent about it.But you are right, I shouldn't refer to this as "use ISO8601" because it is only one of the numeous possible formats described by that spec.
https://stackoverflow.com/questions/1732348/regex-match-open...
:)
Just point him in the right direction and move on.
I am way less judgemental now and a lot of the comments here are making me rethink what I thought about him saying this. He had a lot of other issues and resigned after a couple of days so I guess we'll never know what he was capable of.
EDIT: also I wouldn’t consider this egregious. If the Senior explains and the person was happy to learn something then that’s a good outcome. If they are stubborn about it, then that wouldn’t be great.
I've seen far worse things than this done to a SQL database though…
Just have a look at the list from Wikipedia [1] and notice how many repeats there are.
As an example AMT could be either UTC+4 or UTC-4.
And this doesn't even includes the various local acronyms that people use around the world.
[1] https://en.wikipedia.org/wiki/List_of_time_zone_abbreviation...
If you don't use these, you will inevitably be somewhat wrong due to leap issues, political changes in time, or the like.
IANA time zone identifiers are fully-qualified and unambiguous like America/Los_Angeles or Asia/Kolkata.
If you are trying to store dates and not timestamps, that’s what you want, otherwise equality tests might not work right.
> (The integers stored are usually POSIX timestamps.)
For date types, if they exist distinctly, usually not.
How does that solve the problem? All this would do is give you snapshots of the state of the DB at particular points in time.
The only way to know who changed what when is to keep track of those changes as they are made, and the best way to do that is to stick the changes in an eventlog table.