Formatting dates in .NET
When creating a dynamic folder structure from a date, escaping the backslash can be a bit tricky. For example,
$"{DateTime.Now:yyyy}"
will give a string like 2022
(easy), but what about the whole date?
Since the backslash is itself the escape character, escaping it will need four of them:
$"{DateTime.Now:yyyy\\\\MM\\\\dd}"
That’s because it will need to be escaped twice. Once in the string and then once more for the date time parser that parses the dateformat.