String type to DateTime type conversion : Format Exception

Hi,

Your input string is in format “dd/M/yyyy” that’s why it throws invalid datetime exception.
You can change the string format as “dd/M/yyyy”.

DateTime.ParseExact(“15/6/2018”,“dd/M/yyyy”,System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat)

You can refer this link for more format options:
Custom Data and Time string format

3 Likes