datetime convert experts...help wanted

Discussion in 'ASP .Net' started by =?Utf-8?B?ZGF2ZQ==?=, Jun 1, 2006.

  1. 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
    =?Utf-8?B?ZGF2ZQ==?=, Jun 1, 2006
    #1
    1. Advertising

  2. 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


    "dave" <> wrote in message
    news:...
    >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
    >
    >
    >
    Ken Cox [Microsoft MVP], Jun 1, 2006
    #2
    1. Advertising

  3. =?Utf-8?B?ZGF2ZQ==?=

    Mark Rae Guest

    "dave" <> wrote in message
    news:...

    >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).
    Mark Rae, Jun 2, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harvey
    Replies:
    0
    Views:
    654
    Harvey
    Jul 16, 2004
  2. Harvey
    Replies:
    1
    Views:
    810
    Daniel
    Jul 16, 2004
  3. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    674
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  4. Tim Peters
    Replies:
    0
    Views:
    513
    Tim Peters
    Sep 9, 2003
  5. mp
    Replies:
    1
    Views:
    368
    John Machin
    Jul 28, 2006
Loading...

Share This Page