title: Convert date in file from yyyyMMdd to store in SQL as MMddYYYY
body: <p>I have a file with dates in this format: 20150530. I need to format them into the following format: 05302015 before inserting them into a SQL table.  My original code was:</p>
  
  <pre><code>private string NormalizeDate(string strInput)
      {
          string strOutput;
          DateTime date;
  
  
          if (DateTime.TryParseExact(strInput, "YYYYMMdd", null, System.Globalization.DateTimeStyles.None, out date))
          {
              strOutput = date.ToString("MMddYYYY");
              return strOutput.Trim();
          }
          else
          {
  
              return strInput.Trim();
          }
      }
  </code></pre>
  
  <p>However, the format of the date is not changing before I insert into SQL.  I wanted the date to be in the format of MMddYYYY (with no dashes or spaces) when I insert into my table.  Then with that format I need to merge those dates into a different table but the format needs to be MMddYYYY.</p>
  
  <p>The only other option I would have is to have some kind of query that can take the original date from lets say Table1 (20150530) and then convert the format to Table2 in the format of (05302015).  I am trying not to confuse anyone.  The data type of Table1 is datetime and the column it will be inserted into Table2 is nvarchar.</p>