Problem converting dates to non-US format

J

John

Hi

I am using the below code to assign a date (entered in uk format) to a
datetime variable.

Dim myDateTimeUK As System.DateTime
Dim ukCulture As CultureInfo = New CultureInfo("en-GB")

myDateTimeUK = System.DateTime.Parse(txtDOB.Text, ukCulture.DateTimeFormat)

The problem is that I get the 'System.FormatException: String was not
recognized as a valid DateTime' if the value of txtDOB.Text is 16/12/85
which is a valid uk. It however works if txtDOB.Text is 12/16/85 (us
format). What is the problem and how do I get the text box to accept a uk
format date?

Thanks

Regards
 
K

Katy King

From: "John" <[email protected]>
| I am using the below code to assign a date (entered in uk format) to a
| datetime variable.
|
| Dim myDateTimeUK As System.DateTime
| Dim ukCulture As CultureInfo = New CultureInfo("en-GB")
|
| myDateTimeUK = System.DateTime.Parse(txtDOB.Text,
ukCulture.DateTimeFormat)
|
| The problem is that I get the 'System.FormatException: String was not
| recognized as a valid DateTime' if the value of txtDOB.Text is 16/12/85
| which is a valid uk. It however works if txtDOB.Text is 12/16/85 (us
| format). What is the problem and how do I get the text box to accept a uk
| format date?

Hi John,

I would expect that code to do what you want. When I try running the same
code (on my US machine),
it parses the UK date and fails on the US date.

What is the value of ukCulture.DateTimeFormat.ShortDatePattern?

Katy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top