By default date understand mm/dd/yyyy format. You can parse string date into dd/mm/yyyy using different options.
In this article we will see the options to change string date in dd/mm/yyyy format into DateTime. If you try to convert a date in dd/mm/yyyy (say 17/03/2020), it will throw exception "FormatException: String was not recognized as a valid DateTime". To overcome, follow anyone from below methods.
Use anyone of below method and you are done.
void ConvertDate(string date)
{
if (!string.IsNullOrWhiteSpace(date))
{
string[] splittedDate = date.Split('/');
DateTime date1 = new DateTime(Convert.ToInt32(splittedDate[2]),
Convert.ToInt32(splittedDate[1]), Convert.ToInt32(splittedDate[0]));
DateTime date2 = Convert.ToDateTime(date,
System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
DateTime date3 = DateTime.ParseExact(date, @"d/M/yyyy",
System.Globalization.CultureInfo.InvariantCulture);
DateTime date4;
bool isSuccess = DateTime.TryParse(date, out date4);
}
}
Hope this helps you.