Question Locked

converting from string to date

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,
I'm running an ASP.net program with VB.NET, At one point I try to convert
a date string into a date object... this string is from a TextBox, when I use:
Dim CheckinDate As DateTime = DateTime.Parse(TextBox1.Text)

it comes an error that says:
Conversion failed when converting date and/or time from character string.

by the way I'm using the format of "dd/mm/yyyy"

Plz can any one help me with this
Thanks in advance

3 replies

by thumbsup2

Have you looked at the data to confirm there are no unescaped special characters in it, including spaces, or numbers which would amount to an invalid day/month in it?

Perhaps you need to parse the data into separate variables, one for day, one for month and one for year, then display those results on the screen while in testing mode.

by tony hopkinson

default format on whatever machine is running the code. Gets iffy especillay with mm/dd/yyy and dd/mm/yyyy adn other ambiguous formats

Use the ParseExact method instead.

HtHs

This discussion is closed to new replies.