Q:

DateTime ToString not formatting correctly with ddMMy specifier

I have the following format for my DateTime.ToString:
ddMMy

However this format returns a date with two digits for the year i.e. 16 instead of 6. See the following code example:
DateTime dt = new DateTime(2016, 9, 12);
Console.WriteLine(dt.ToString("ddMMyy"));

This displays:

120916

Instead of the expected:

12096

To further complicate things the following code:
string date = "12096";
Console.WriteLine(DateTime.ParseExact(date, "ddMMy", System.Globalization.CultureInfo.CurrentCulture, 
    System.Globalization.DateTimeStyles.None).ToString("yyyyMMdd"));

Produces the output:

20060912

Is there a format I can pass to get my required output of 13096 or is this a bug in the DateTime.ToString implementation?

A:

You seem to misunderstand the doubling of the format specifiers. 
y does not output the last digit of the year only. It outputs 9 for 2009, but 16 for 2016, whereas yy outputs 09 for 2009 and 16 for 2016. This is also true for other format specifies.
Examples: Consider July 1st 2005
dMy => 175
dMyy => 1705
dMMyy => 10705
ddMMyy => 010705

A general rule is: If you use a single letter, there will be no leading zeros. If you use two letters, there may be leading zeros. More letters provide additional options specific to the date part (for example, yyyy provides the full year, MMMprovides the shortened month name).
To solve your problem, I'd combine date formatting with maths. You could try this:
string date = dt.ToString("ddMM") + (dt.Year % 10).ToString();

For your parsing issue: Because of what I said above you can conclude that parsing 12096 as 206-09-12 is entirely correct. If it was 2016, the previous formatting would have output 16. The fact that your year-part in the string consists only of a 6 and you're not "forcing" leading zeros causes the algorithm to consider the single 6 as 2006. Everything is fine so far.
This: Even if you use my above example for formatting 2016 as 6, parsing will always produce 2006instead of 2016. 
Short: If you want 2016, make sure to put the 16 in your string, not just 6.

