Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date'is not valid(System.InvalidCastException)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kiran

    Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date'is not valid(System.InvalidCastException)

    Hi,

    I am trying to convert a string(Thu Jul 21 00:00:00 UTC+0100 200) to
    date. I get the following error

    Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date' is
    not valid(System.In validCastExcept ion)

    Any help on this will be appreciated

    Thanks
    Kiran
  • Cor Ligthert [MVP]

    #2
    Re: Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date' is not valid(System.In validCastExcept ion)

    Kiran,

    Is the string format "Thu Jul 21 00:00:00 UTC+0100 200" a valid date in your
    culture and calendersetting s?

    Cor


    Comment

    • Kiran

      #3
      Re: Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date'is not valid(System.In validCastExcept ion)

      Cor Ligthert [MVP] wrote:[color=blue]
      > Kiran,
      >
      > Is the string format "Thu Jul 21 00:00:00 UTC+0100 200" a valid date in your
      > culture and calendersetting s?
      >
      > Cor
      >
      >[/color]
      Hi Cor,

      yes it is a valid date and I am getting the value from javascript and
      this is the value I get from clientside.

      "Thu Jul 21 00:00:00 UTC+0100 2005"

      Thanks
      Kiran

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date' is not valid(System.In validCastExcept ion)

        Kiran,
        [color=blue]
        > yes it is a valid date and I am getting the value from javascript and this
        > is the value I get from clientside.
        >
        > "Thu Jul 21 00:00:00 UTC+0100 2005"
        >[/color]
        Can you tell what culture this is in?

        Otherwise it is impossible to simulate it.

        Cor




        Comment

        • Kiran

          #5
          Re: Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date'is not valid(System.In validCastExcept ion)

          Cor Ligthert [MVP] wrote:[color=blue]
          > Kiran,
          >
          >[color=green]
          >>yes it is a valid date and I am getting the value from javascript and this
          >>is the value I get from clientside.
          >>
          >>"Thu Jul 21 00:00:00 UTC+0100 2005"
          >>[/color]
          >
          > Can you tell what culture this is in?
          >
          > Otherwise it is impossible to simulate it.
          >
          > Cor
          >
          >
          >
          >[/color]

          Hi Cor

          The culture is "en-GB"

          Thanks
          Kiran

          Comment

          • Cor Ligthert [MVP]

            #6
            Re: Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date' is not valid(System.In validCastExcept ion)

            Kiran,
            [color=blue][color=green]
            >>[color=darkred]
            >>>yes it is a valid date and I am getting the value from javascript and
            >>>this is the value I get from clientside.
            >>>
            >>>"Thu Jul 21 00:00:00 UTC+0100 2005"
            >>>[/color]
            >>
            >> Can you tell what culture this is in?
            >>
            >> Otherwise it is impossible to simulate it.
            >>[/color]
            >
            > The culture is "en-GB"
            >[/color]
            Kiran,

            I can be terrible wrong, however this is maybe a valid date, however not in
            the context from how a datetime has to be in a string in the culture en-GB
            to be valid to cast.

            One of those is
            04/08/05 for today

            Maybe some persons from that culture, which I know are active here, can give
            some samples of those.

            I hope this helps

            Cor


            Comment

            • Kiran

              #7
              Re: Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date'is not valid(System.In validCastExcept ion)

              Cor Ligthert [MVP] wrote:[color=blue]
              > Kiran,
              >
              >[color=green][color=darkred]
              >>>>yes it is a valid date and I am getting the value from javascript and
              >>>>this is the value I get from clientside.
              >>>>
              >>>>"Thu Jul 21 00:00:00 UTC+0100 2005"
              >>>>
              >>>
              >>>Can you tell what culture this is in?
              >>>
              >>>Otherwise it is impossible to simulate it.
              >>>[/color]
              >>
              >>The culture is "en-GB"
              >>[/color]
              >
              > Kiran,
              >
              > I can be terrible wrong, however this is maybe a valid date, however not in
              > the context from how a datetime has to be in a string in the culture en-GB
              > to be valid to cast.
              >
              > One of those is
              > 04/08/05 for today
              >
              > Maybe some persons from that culture, which I know are active here, can give
              > some samples of those.
              >
              > I hope this helps
              >
              > Cor
              >
              >[/color]
              Hi Cor,

              you got me wrong, I get this value from clientside(from a ultrawebgrid
              control).

              On the server side I want to convert this value to date so that I can
              use it.

              Thanks
              kiran

              Comment

              • Cor Ligthert [MVP]

                #8
                Re: Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date' is not valid(System.In validCastExcept ion)

                [color=blue]
                > you got me wrong, I get this value from clientside(from a ultrawebgrid
                > control).
                >
                > On the server side I want to convert this value to date so that I can use
                > it.[/color]

                Therefore you have first to translate it (as what I assume this is not a
                valid en-GB format) to a string that is in a valid format to make it able to
                be used in CDate, parse or convert.

                You have all the ingredients, so when it would have to be
                21/07/2005 you can use something as Regex to do that

                RegexLib


                Expresso


                I hope this helps a little bit?

                Cor



                Comment

                • Kiran

                  #9
                  Re: Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date'is not valid(System.In validCastExcept ion)

                  Cor Ligthert [MVP] wrote:[color=blue][color=green]
                  >>you got me wrong, I get this value from clientside(from a ultrawebgrid
                  >>control).
                  >>
                  >>On the server side I want to convert this value to date so that I can use
                  >>it.[/color]
                  >
                  >
                  > Therefore you have first to translate it (as what I assume this is not a
                  > valid en-GB format) to a string that is in a valid format to make it able to
                  > be used in CDate, parse or convert.
                  >
                  > You have all the ingredients, so when it would have to be
                  > 21/07/2005 you can use something as Regex to do that
                  >
                  > RegexLib
                  > http://www.regexlib.com/Default.aspx
                  >
                  > Expresso
                  > http://www.ultrapico.com/Expresso.htm
                  >
                  > I hope this helps a little bit?
                  >
                  > Cor
                  >
                  >
                  >[/color]
                  Thanks Cor, I got it working.

                  I translated the date in client side.

                  Thanks
                  Kiran

                  Comment

                  • Jay B. Harlow [MVP - Outlook]

                    #10
                    Re: Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date' is not valid(System.In validCastExcept ion)

                    Kiran,
                    Are you using CDate or DateTime.ParseE xact. It sounds like you are using
                    CDate, when you should be using DateTime.ParseE xact. Something like:

                    Dim input As String = "Thu Jul 21 00:00:00 UTC+0100 2005"

                    Const format As String = "ddd MMM dd hh:mm:ss \U\T\Czzzz yyyy"
                    Dim value As DateTime = DateTime.ParseE xact(input, _
                    format, System.Globaliz ation.CultureIn fo.InvariantCul ture)

                    For details on custom datetime formats see:



                    For information on formatting in .NET in general see:


                    Hope this helps
                    Jay

                    Hope this helps
                    Jay

                    "Kiran" <kiran@nospam.n et> wrote in message
                    news:uI0QzTNmFH A.1416@TK2MSFTN GP09.phx.gbl...
                    | Hi,
                    |
                    | I am trying to convert a string(Thu Jul 21 00:00:00 UTC+0100 200) to
                    | date. I get the following error
                    |
                    | Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date' is
                    | not valid(System.In validCastExcept ion)
                    |
                    | Any help on this will be appreciated
                    |
                    | Thanks
                    | Kiran


                    Comment

                    • Cor Ligthert [MVP]

                      #11
                      Re: Cast from string &quot;Thu Jul 21 00:00:00 UTC+0100 200&quot; to type 'Date' is not valid(System.In validCastExcept ion)

                      Jay,

                      That was probably not a one minute puzzle

                      However nice. (I remember me this one now)

                      :-)

                      Cor


                      Comment

                      Working...