How does CultureInfo.InvariantCulture and DateTime to String works
<p>I've been looking for information on Internet about this optional parameter CultureInfo.InvariantCulture when formatting in .NET</p>

<p>These articles explains about it: <a href="https://stackoverflow.com/questions/9760237/what-does-cultureinfo-invariantculture-mean">What does cultureinfo invariantculture mean</a> , <a href="https://stackoverflow.com/questions/2423377/what-is-the-invariant-culture">What is the invariant culture</a>. But it's still not clear for me.</p>

<p>I want to manage and save a datetime variable as this format 'yyyyMMdd' and I formatted it like this:</p>

<pre><code>DateTime localDateTime = DateTime.Today; //&gt; 2016-02-10 12:33
string formattedDateTime = localDateTime.ToString("yyyyMMdd"); //&gt; 20160210
</code></pre>

<p>It is suppossed to have a varchar column in db with a length of 8. But in a specific case it started to save 7 chars. I'm waiting to get access to our client's domain to check the saved format.</p>

<p>However, each user can set no matter what culture in the system (e.g. "en", "es", "fr"), so even if the method ToString which is forced to format like this "YYYYMMDD", do I need to set the invariant culture? If not, I could risk to have my datetime in string with another format? Does the regional configuration in database server matter?</p>

<p>This is that I'm attempting to do right now, but not sure if this will fix the problem after we check in tests:</p>

<pre><code>DateTime localDateTime = DateTime.Today;
string formattedDateTime = localDateTime.ToString("yyyyMMdd", CultureInfo.InvariantCulture); //&gt; 20160210
</code></pre>

<p>This is another scope, if I need to build my variable from database and save it in a stored procedure, I'm doing this:</p>

<pre><code>CONVERT(varchar, getdate(), 112) --ISO for yyyymmdd
</code></pre>

<hr>

<p><strong>EDIT:</strong></p>

<p>We did some tests:</p>

<pre><code>DateTime currentDateTime = dateParameter; // 10/2/16 12:33 PM
string dateParameterAsString = dateParameter.ToString(); // "10/2/16 12:33 PM"
string formattedIdentifier = dateParameter.ToString(System.Globalization.CultureInfo.InvariantCulture); // "02/10/2016 12:33:00"
string formattedIdentifier2 = dateParamter.ToString("yyyyMMdd"); // "20160218"
string formattedIdentifier3 = dateParamter.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture); // "20160218"
</code></pre>