I have the following code:
Dim dtDoM As Nullable(Of DateTime)
If (txtMarriageDate.Text.Trim = "") Then
dtDoM = Nothing
Else
dtDoM = DateTime.ParseExact(txtMarriageDate.Text.Trim + " 00:00:00", "dd/MM/yyyy hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture)
'dtDoM = Convert.ToDateTime(txtMarriageDate.Text)
End If
On the commented out section I was getting FormatException ‘String not recognized as datetime’ and on the new code I’m getting “System.FormatException = {“The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.”}”
EDIT: Answered. Can’t believe I overlooked that.
Your date (01/25/1955) is in
MM/dd/yyyyformat, you’re usingdd/MM/yyyyin your format string.Try using this:
"MM/dd/yyyy hh:mm:ss"