I am trying to filter through things by date. I have 2 DateTimePicker called FromDate and ToDate. I have an array and within one of the array (str[10]) is a date, I tried converting the string into a datetime format but I still get the error:
System.FormatException: 'String was not recognized as a valid DateTime.'
The string within str[10]:
str[10] = "9/22/2017 18:24";
My current code:
string[] date = str[10].Split(' ');
DateTime dateSpec = DateTime.ParseExact(date[0], "MM/dd/yyyy", CultureInfo.CurrentCulture);
if (dateSpec >= FromDate.Value && dateSpec <= ToDate.Value)
{
//Do Something
}
I am not so sure what to do as most forums suggest more or less the same thing. I'm not sure where the error is. I checked the array and the string does not have any spaces as well, thinking that it may have been the reason as to why there was an error
"MM/dd/yyyy"?DateTime.Parse