I have a jquery datepicker in a usercontrol. On the usercontrol i have a property that will return the selected date to the page which contains my usercontrol.
I try to convert the string to a date:
Dim MyDate As System.DateTime = System.Convert.ToDateTime(txtFromDateF.Value, System.Globalization.DateTimeFormatInfo.InvariantInfo)
i keep getting the error:
String was not recognized as a valid DateTime.
The date which is in de txtFromDateF => 23-06-2015
I thought that the "InvariantInfo" would make sure that I always get the date in the correct format, no matter what my language-setting is.
Best How To :
doesn't contain format pattern
From MSDN about InvariantCulture
The InvariantCulture property can be used to persist data in a culture-independent format. This provides a known format that does not change
For using invariant format in converting
DateTime your string value must be formatted with one of invariant culture format patterns.
for checking/printing all patterns
For custom formatted strings you can use DateTime.TryParseExact method
Dim datevalue As Stirng = "23-06-2015"
Dim customFormat As String = "dd-MM-yyyy"
Dim yourdate As DateTime
yourdate) = True Then
'Use parsed DateTime value
'Notice about wrong formatted date