I have set my form up with a DateTimePicker with the format of #dd MMMM yyyy dddd hh.mm tt#
When the date and time have been selected the data is stored in an xml file for example as
"22 April 2021 Thursday 10.01 PM"
However, when I try and retrieve the data to populate the DateTimePicker box I get this error
System.FormatException: 'String was not recognized as a valid DateTime.'
If I truncate the data in the xml file to "22 April 2021" the code runs and "22 April 2021 Thursday 12.00 AM" is displayed in the DateTimePicker box.
I have included a subroutine
Public Sub SetMyCustomFormat()
' Set the Format type and the CustomFormat string.
DatePicker.Format = DateTimePickerFormat.Custom
DatePicker.CustomFormat = "dd MMMM yyyy dddd hh.mm tt"
End Sub 'SetMyCustomFormat for dates
Line of code that causes the problem is
DatePicker.Text = node.SelectSingleNode("DatePicker", nsmgr).InnerText
It seems the format expected is "dd MMMM yyyy"
Anybody got any ideas?
What I have tried:
Searched the internet but no answers found.