Quantcast
Channel: VB.Net convert String to Datetime
Viewing all articles
Browse latest Browse all 6

VB.Net convert String to Datetime

$
0
0

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


Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images