parse dates

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

    #1

    parse dates

    I need to be able to parse both of these dates with the same method, and
    return them as a DateTime object. Is there any methods that would do this
    blindly or do I need to provide the format?

    Feb 25 23:11

    Dec 1 2002


  • Miha Markic

    #2
    Re: parse dates

    Hi,

    You might try DateTime.Parse using InvariantCultur e:

    DateTime dt = DateTime.Parse( yourdate,
    System.Globaliz ation.CultureIn fo.InvariantCul ture)

    Miha

    "memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
    news:TCyRa.5459 6$o86.30546@new s1.central.cox. net...[color=blue]
    > I need to be able to parse both of these dates with the same method, and
    > return them as a DateTime object. Is there any methods that would do this
    > blindly or do I need to provide the format?
    >
    > Feb 25 23:11
    >
    > Dec 1 2002
    >
    >[/color]


    Comment

    • memememe

      #3
      Re: parse dates

      thanks for the idea, but it didnt work :-(
      im actually starting to think that it might be a good idea to try catch it
      with one format using parseexact and if it fails, I try the other format, of
      course that only works if those are the two only possible formats, which I
      am not sure they are.


      "Miha Markic" <miham@spin.NO. SPAM.si> wrote in message
      news:%23cdCPLHT DHA.2228@tk2msf tngp13.phx.gbl. ..[color=blue]
      > Hi,
      >
      > You might try DateTime.Parse using InvariantCultur e:
      >
      > DateTime dt = DateTime.Parse( yourdate,
      > System.Globaliz ation.CultureIn fo.InvariantCul ture)
      >
      > Miha
      >
      > "memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
      > news:TCyRa.5459 6$o86.30546@new s1.central.cox. net...[color=green]
      > > I need to be able to parse both of these dates with the same method, and
      > > return them as a DateTime object. Is there any methods that would do[/color][/color]
      this[color=blue][color=green]
      > > blindly or do I need to provide the format?
      > >
      > > Feb 25 23:11
      > >
      > > Dec 1 2002
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Mihai N.

        #4
        Re: parse dates

        > You might try DateTime.Parse using InvariantCultur e:
        Why with InvariantCultur e?

        Mihai

        Comment

        • Miha Markic

          #5
          Re: parse dates

          It never changes (it is not regional setting dependent) - it is fixed and
          you are certain what you'll get.

          Miha

          "Mihai N." <nmihai_2000@ya hoo.com> wrote in message
          news:Xns93BCD44 3CF51MihaiN@204 .127.204.17...[color=blue][color=green]
          > > You might try DateTime.Parse using InvariantCultur e:[/color]
          > Why with InvariantCultur e?
          >
          > Mihai[/color]


          Comment

          • Mihai N.

            #6
            Re: parse dates

            > It never changes (it is not regional setting dependent) - it is fixed and[color=blue]
            > you are certain what you'll get.[/color]
            I know this. I was just not my understanding that he wanted something
            regional setting independent.
            I think he was just trying to solve his problem in English, without thinking
            what happens if in 2 months the marketing guys will ask for German.
            [color=blue]
            > I need to be able to parse both of these dates with the same method, and
            > return them as a DateTime object. Is there any methods that would do this
            > blindly or do I need to provide the format?[/color]

            My normal answer would be: use DateTime.Parse.
            And depending on what you need, you may use a CultureInfo or not,
            invariant or not.

            Mihai

            Comment

            • Mihai N.

              #7
              Re: parse dates

              > It never changes (it is not regional setting dependent) - it is fixed and[color=blue]
              > you are certain what you'll get.[/color]
              I know this. I was just not my understanding that he wanted something
              regional setting independent.
              I think he was just trying to solve his problem in English, without thinking
              what happens if in 2 months the marketing guys will ask for German.
              [color=blue]
              > I need to be able to parse both of these dates with the same method, and
              > return them as a DateTime object. Is there any methods that would do this
              > blindly or do I need to provide the format?[/color]

              My normal answer would be: use DateTime.Parse.
              And depending on what you need, you may use a CultureInfo or not,
              invariant or not.

              Mihai

              Comment

              • memememe

                #8
                Re: parse dates


                "Mihai N." <nmihai_2000@ya hoo.com> wrote in message
                news:Xns93BD19C 83945MihaiN@204 .127.204.17...[color=blue][color=green]
                > > It never changes (it is not regional setting dependent) - it is fixed[/color][/color]
                and[color=blue][color=green]
                > > you are certain what you'll get.[/color]
                > I know this. I was just not my understanding that he wanted something
                > regional setting independent.
                > I think he was just trying to solve his problem in English, without[/color]
                thinking[color=blue]
                > what happens if in 2 months the marketing guys will ask for German.
                >[color=green]
                > > I need to be able to parse both of these dates with the same method, and
                > > return them as a DateTime object. Is there any methods that would do[/color][/color]
                this[color=blue][color=green]
                > > blindly or do I need to provide the format?[/color]
                >
                > My normal answer would be: use DateTime.Parse.
                > And depending on what you need, you may use a CultureInfo or not,
                > invariant or not.
                >
                > Mihai[/color]

                I actually solved the problem we had by first calling parse, if that failed,
                I would call parseExact and I would give it a formats array tht contained
                what we consider valid formats so far. The reason I didnt do just the
                parseExact call is because there is a lot of possible date formats we might
                get that might not be on our formats array but maybe the parse method would
                understand.


                Comment

                Working...