Dynamically Changing Date Separators at Runtime in C# & .NET
[C#, .NET]
In our previous post, “Working With / The Date Separator In C# & .NET”, we looked at the runtime interpretation of the DateSeparator and how to force display of a particular symbol.
In this post, we will look at how to do it properly.
We will use the strategy I first outlined in the post “Dynamically Changing Date Separators At Runtime”, where we took an existing culture and modified it for our purposes.
Here, we are going to extract the DateTimeFormatInfo for the current culture and modify it to change the DateSeparator. In our case, we want to use the + as a date separator.
using System.Globalization;
// Clone the existing culture and extract the DateTimeFormatInfo
var dateTimeFormatInfo = (DateTimeFormatInfo)
CultureInfo.InvariantCulture.DateTimeFormat.Clone();
// Modify what we want to change - the date separator
dateTimeFormatInfo.DateSeparator = "+";
// Now, when formatting, specify our format
Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy", dateTimeFormatInfo));
Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy"));
If you run this code, you will see good news and bad news.

- When we remember to pass the culture, it does what we want
- If we forget, we get the default behaviour
This is not ideal.
The proper solution is to *modify the culture directly**.
We shall do that as follows:
- Clone the current culture, or create one that may be more suited as a base
- Modify whatever you need
- Set the Thread’s current culture to our new custom culture
- Forget about formatting issues
using System.Globalization;
// Clone the current culture, to use as a base
var culture = CultureInfo.InvariantCulture.Clone() as CultureInfo;
// Modify what we want to change - the date separator
culture!.DateTimeFormat.DateSeparator = "+";
// Set the thread's culture to our new culture
Thread.CurrentThread.CurrentCulture = culture;
// Work as normal
Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy"));

You can see here that we now don’t need to pass anything to our ToString overload - the runtime natively knows what to use as a DateSeparator.
TLDR
To avoid having to pass Cultures to your code when formatting, change the CurrentCutlure directly to one with all your configurations made.
The code is in my GitHub.
Happy hacking!