Firstly, if you are specifically entering the date as a 6-digit string then why would you use a 4-character format string? Secondly, if the user enters a two-part code that is separated by a dash and you only want to parse the part before the dash then you need to get just that part and pass that to ParseExact. It's very easy to get just that part of the text and it's very easy to find out how to do that.
As for the issue, as the name suggests, a DateTime
contains a date and a time. Internally, it is just a number that is an offset from a specific moment in time. If you want to represent just a date with a DateTime
value then you simply set the time part to zero, i.e. midnight. When it comes to displaying a DateTime
value, it's completely up to you what the output looks like. It needs to be converted to a String
for display purposes so, if you want a specific format, you should convert it to a String
yourself and specify the format you want, rather than leaving the conversion up to the system and assuming that it will magically know what format you want of the many possible choices. Again, it's very easy to find out how to convert a DateTime
to a String
in a specific format, so I'll leave that part to you.