Sibusiso Shongwe Sibusiso Shongwe - 4 months ago 26
C# Question

How do I prevent `DateTime.ParseExact();` from returning time

Am using

DateTime.ParseExact(date, "yyMMdd", CultureInfo.InvariantCulture).ToString();
to change a date in a number format to a date, I ado get the date but it also returns the time part but I would like it to be the date only my, here is my code below.

String date = TextBox3.Text.Trim();
Label9.Text = DateTime.ParseExact(date, "yyMMdd", CultureInfo.InvariantCulture).ToString();

for Input : 940226 i get the output: 02/26/1994 00:00:00 I want to remove the time part


Well, while it is of course possible to use a custom date/time format, for the sake of globalization I suggest you use one of the methods that return the date as string based on the system's current culture information. Like for example:

DateTime date = DateTime.ParseExact(strDate, "yyMMdd",CultureInfo.InvariantCulture);
Label9.Text = date.ToShortDateString();