VB.Net convert String to Datetime

Jimmy-NZ 1 Reputation point
2020-07-18T23:22:47.12+00:00

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

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,798 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2020-07-18T23:29:15.047+00:00

    Visual basic .Net is not currently supported here on QnA. They're actively answering questions in dedicated forums here.
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral

    --please don't forget to Accept as answer if the reply is helpful--


    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.