There's bad date handling code. There's bad date formatting code. There's bad date handling code that abuses date formatting to stringify dates. There are cases where the developer clearly doesn't know the built-in date methods, and cases where they did, but clearly just didn't want to use them.
There's plenty of apocalypticly bad date handling options, but honestly, that gets a little boring after awhile. My personal favorite will always be the near misses. Code that almost, but not quite, "gets it".
Karl's co-worker provided a little nugget of exactly that kind of gold.
formattedID = DateTime.Now.ToString("dd / MM / yyyy").Replace(" / ", "")
Here, they understand that a ToString
on a DateTime
allows you to pass a format string. They even understand that the format string lets you customize the separators (or they think spaces are standard in date formats). But they didn't quite make the leap to thinking, "hey, maybe I don't need to supply separators," so they Replace
them.
There are probably a few other replacements that need to be made in the codebase.