VB.Net convert String to Datetime

  • Thread starter Thread starter Jimmy NZ2010
  • Start date Start date
J

Jimmy NZ2010

Guest
Hi there,

In my VB.net project, a time String 8:40 a.m. was converted to date as shown in the code:
Dim dtDate As Date
dtDate = CDate(" 8:40 a.m.")


it worked on Win7 32-bit without problem but it caused an Exception: "Conversion from string "8:40 a.m." to type 'Date' is not valid" in Win10 64-bit

I tried replacing CDate() with Convert.ToDateTime() and run it in Win10 64-bit but got Got Exception: The string was not recognized as a valid DateTime. There is a unknown word starting at index 5
The code is shown below:


Dim strTime as String = “8:40 a.m.”
Dim dtStart As DateTime = Convert.ToDateTime(strTime)
Got Exception: The string was not recognized as a valid DateTime. There is a unknown word starting at index 5



Could you please advise a solution?

Thanks
Jimmy-NZ


Continue reading...
 
Back
Top