Your format should be as follows:
string format = "dd-MM-yyyy";
Casing is important with string formatting, you may think it strange that the month uses upper-case, but this is because lower case m
and mm
is used to represent minutes.
Note that the reason your output displays DD
and YYYY
is because any character that is not reserved as a format character will be outputted with no change. Uppercase D
and Y
are not reserved which is why they display in the output, just as -
remains unchanged.
If you wish to output reserved format characters then you can escape them using \
.