datetime convert experts...help wanted

G

Guest

I have a string "05142000" i want it converted to a date.

Any good clean ways of doing this without reverting to string manipulation?

I have tried
mydate = Date.ParseExact("05142000", "ddMMyyyy", Nothing) but it complains
about "string is not supported in calendar
System.Globalization.GregorianCalendar"

any ideas?
thx
 
K

Ken Cox [Microsoft MVP]

Hi Dave,

To avoid parsing the string and creating a date from the components (pretty
easy), you might have to create a custom culture that uses that string to
represent a date. Then you'd have to create a custom DateTimeFormatInfo to
apply to it.

Sounds like a lot of trouble compared with pulling off 2, 2 and 4 characters
from the existing string.

Ken
 
M

Mark Rae

I have a string "05142000" i want it converted to a date.

Any good clean ways of doing this without reverting to string
manipulation?

I have tried
mydate = Date.ParseExact("05142000", "ddMMyyyy", Nothing) but it
complains
about "string is not supported in calendar
System.Globalization.GregorianCalendar"

Well it would do...take a step back and look at your code. You're telling it
to make a DateTime variable where the day part is 05, the month part is 14
and the year part is 2000. Change the second argument to "MMddyyyy" and you
should be fine).
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top