Convert to date

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

    Convert to date

    I get from the dateTimePicker the value: string="12/18/2003 11:52:28 AM"

    Now I need to convert this to dateTime. Any function I use: Convert.ToDateT ime(string) or Cdate(string), I get an error message:
    String was not recognized as a valid DateTime.

    What should I do?
    Use replace function and mid function on string and at the end convert it to date?

    Thank you for your answer,
    Simon
  • Herfried K. Wagner [MVP]

    #2
    Re: Convert to date

    * "simon" <simon.zupan@st ud-moderna.si> scripsit:[color=blue]
    > I get from the dateTimePicker the value: string="12/18/2003 11:52:28 AM"
    >
    > Now I need to convert this to dateTime. Any function I use: Convert.ToDateT ime(string) or Cdate(string), I get an error message:
    >
    > String was not recognized as a valid DateTime.[/color]

    Did you try it with 'DateTime.Parse ' or 'DateTime.Parse Exact'?

    --
    Herfried K. Wagner [MVP]
    <http://www.mvps.org/dotnet>

    Comment

    • Armin Zingler

      #3
      Re: Convert to date

      "simon" <simon.zupan@st ud-moderna.si> schrieb[color=blue]
      > I get from the dateTimePicker the value: string="12/18/2003 11:52:28
      > AM"
      >
      > Now I need to convert this to dateTime. Any function I use:
      > Convert.ToDateT ime(string) or Cdate(string), I get an error message:
      > String was not recognized as a valid DateTime.
      >
      > What should I do?
      > Use replace function and mid function on string and at the end
      > convert it to date?[/color]

      You're from Slovenia? Do you have the English date/time format? Here in
      Germany it is dd.mm.yyyy hh:mm:ss, so ConvertToDateTi me("18.12.2003
      11:52.28") works.


      --
      Armin




      Comment

      • simon

        #4
        Re: Convert to date

        I tried with 'DateTime.Parse ' and 'DateTime.Parse Exact' and still doesn't
        work, the same error message.

        Thank you,
        Simon

        "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
        news:brsj90$776 12$3@ID-208219.news.uni-berlin.de...[color=blue]
        > * "simon" <simon.zupan@st ud-moderna.si> scripsit:[color=green]
        > > I get from the dateTimePicker the value: string="12/18/2003 11:52:28 AM"
        > >
        > > Now I need to convert this to dateTime. Any function I use:[/color][/color]
        Convert.ToDateT ime(string) or Cdate(string), I get an error message:[color=blue][color=green]
        > >
        > > String was not recognized as a valid DateTime.[/color]
        >
        > Did you try it with 'DateTime.Parse ' or 'DateTime.Parse Exact'?
        >
        > --
        > Herfried K. Wagner [MVP]
        > <http://www.mvps.org/dotnet>[/color]


        Comment

        • simon

          #5
          Re: Convert to date

          What you mean? I didn't found founction ConvertToDateTi me?
          Thank you,
          Simon

          "Armin Zingler" <az.nospam@free net.de> wrote in message
          news:e$bwjDYxDH A.1736@TK2MSFTN GP09.phx.gbl...[color=blue]
          > "simon" <simon.zupan@st ud-moderna.si> schrieb[color=green]
          > > I get from the dateTimePicker the value: string="12/18/2003 11:52:28
          > > AM"
          > >
          > > Now I need to convert this to dateTime. Any function I use:
          > > Convert.ToDateT ime(string) or Cdate(string), I get an error message:
          > > String was not recognized as a valid DateTime.
          > >
          > > What should I do?
          > > Use replace function and mid function on string and at the end
          > > convert it to date?[/color]
          >
          > You're from Slovenia? Do you have the English date/time format? Here in
          > Germany it is dd.mm.yyyy hh:mm:ss, so ConvertToDateTi me("18.12.2003
          > 11:52.28") works.
          >
          >
          > --
          > Armin
          >
          > http://www.plig.net/nnq/nquote.html
          > http://www.netmeister.org/news/learn2quote.html
          >[/color]


          Comment

          • Armin Zingler

            #6
            Re: Convert to date

            "simon" <simon.zupan@st ud-moderna.si> schrieb[color=blue]
            > What you mean? I didn't found founction ConvertToDateTi me?[/color]

            A little bit more creativity, please! ;-) Fun only...

            Convert.ToDateT ime

            Dots cost extra. ;-)


            --
            Armin




            Comment

            • Cor

              #7
              Re: Convert to date

              Hi Simon,

              I am also from Europe

              Dim b As New DateTime
              b = Convert.ToDateT ime("18/12/2003 11:52:28 AM")
              MessageBox.Show (b.ToString)

              Works for my

              Cor



              Comment

              • Cor

                #8
                OT: Re: Convert to date

                Hi Armin,

                [color=blue]
                > Germany it is dd.mm.yyyy hh:mm:ss, so ConvertToDateTi me("18.12.2003
                > 11:52.28") works.[/color]

                Really?

                :-)))

                Cor


                Comment

                • Armin Zingler

                  #9
                  Re: Re: Convert to date

                  "Cor" <non@non.com> schrieb[color=blue]
                  >[color=green]
                  > > Germany it is dd.mm.yyyy hh:mm:ss, so
                  > > ConvertToDateTi me("18.12.2003 11:52.28") works.[/color]
                  >
                  > Really?
                  >
                  > :-)))[/color]


                  Yes, really:
                  Private Function ConvertToDateTi me(ByVal s As String) As Date
                  Return Convert.ToDateT ime(s)
                  End Function


                  ;-))

                  --
                  Armin




                  Comment

                  • Cor

                    #10
                    OT: Re: Re: Convert to date

                    Hi Armin,

                    Look again, you know that I would not send it like this if there was not
                    something with it that was something absolute not important.
                    [color=blue][color=green][color=darkred]
                    > > > Germany it is dd.mm.yyyy hh:mm:ss, so
                    > > > ConvertToDateTi me("18.12.2003 11:52.28") works.[/color]
                    > > ------
                    > > Really?
                    > >
                    > > :-)))[/color]
                    >[/color]


                    Comment

                    • Armin Zingler

                      #11
                      Re: Re: Re: Convert to date

                      "Cor" <non@non.com> schrieb[color=blue]
                      > Hi Armin,
                      >
                      > Look again, you know that I would not send it like this if there was
                      > not something with it that was something absolute not important.[/color]

                      I thought you referred to the wrong function name.


                      --
                      Armin

                      [color=blue][color=green][color=darkred]
                      > > > > Germany it is dd.mm.yyyy hh:mm:ss, so
                      > > > > ConvertToDateTi me("18.12.2003 11:52.28") works.
                      > > >
                      > > > ------
                      > > > Really?
                      > > >
                      > > > :-)))[/color][/color][/color]

                      Comment

                      • simon

                        #12
                        Re: Convert to date

                        I read a value from timePicker and it is:

                        start="12/18/2003 11:52:28 AM" String

                        If I watch function now:

                        dim dt as DateTime
                        dt=Now() I get:
                        dt=#12/19/2003 9:09:19 AM# Date
                        so I guess this is my system dateTime format.

                        Then if I use:
                        dt = Convert.ToDateT ime(start)

                        I still get an error message:
                        String was not recognized as a valid DateTime.

                        I don't know what else should I do?

                        Thank you,
                        Simon


                        "Cor" <non@non.com> wrote in message
                        news:e#HTMZYxDH A.1396@TK2MSFTN GP10.phx.gbl...[color=blue]
                        > Hi Simon,
                        >
                        > I am also from Europe
                        >
                        > Dim b As New DateTime
                        > b = Convert.ToDateT ime("18/12/2003 11:52:28 AM")
                        > MessageBox.Show (b.ToString)
                        >
                        > Works for my
                        >
                        > Cor
                        >
                        >
                        >[/color]


                        Comment

                        • Cor

                          #13
                          Re: Convert to date

                          Hi Simon,

                          When I try this I get 3 times the date from now
                          MessageBox.Show (Me.DateTimePic ker1.Value.ToSt ring)
                          Dim b As New DateTime
                          b = Convert.ToDateT ime(Me.DateTime Picker1.Value.T oString)
                          MessageBox.Show (b.ToString)
                          Dim c As DateTime
                          MessageBox.Show (c.Now().ToStri ng)

                          Can you try it also?

                          Cor

                          [color=blue]
                          > I read a value from timePicker and it is:
                          >
                          > start="12/18/2003 11:52:28 AM" String
                          >
                          > If I watch function now:
                          >
                          > dim dt as DateTime
                          > dt=Now() I get:
                          > dt=#12/19/2003 9:09:19 AM# Date
                          > so I guess this is my system dateTime format.
                          >
                          > Then if I use:
                          > dt = Convert.ToDateT ime(start)
                          >
                          > I still get an error message:
                          > String was not recognized as a valid DateTime.
                          >
                          > I don't know what else should I do?
                          >
                          > Thank you,
                          > Simon
                          >
                          >
                          > "Cor" <non@non.com> wrote in message
                          > news:e#HTMZYxDH A.1396@TK2MSFTN GP10.phx.gbl...[color=green]
                          > > Hi Simon,
                          > >
                          > > I am also from Europe
                          > >
                          > > Dim b As New DateTime
                          > > b = Convert.ToDateT ime("18/12/2003 11:52:28 AM")
                          > > MessageBox.Show (b.ToString)
                          > >
                          > > Works for my
                          > >
                          > > Cor
                          > >
                          > >
                          > >[/color]
                          >
                          >[/color]


                          Comment

                          • Phill.  W

                            #14
                            Re: Convert to date

                            "simon" <simon.zupan@st ud-moderna.si> wrote in message
                            news:uQ61EyXxDH A.3408@tk2msftn gp13.phx.gbl...

                            OK, I'm new around here but...
                            [color=blue]
                            > I get from the dateTimePicker the value:
                            > string="12/18/2003 11:52:28 AM"[/color]
                            .. . .[color=blue]
                            > Now I need to convert this to dateTime.[/color]

                            No, you don't.
                            The DateTimePicker' s Value property is /already/ of Type
                            DateTime (not String), so you should be able to use the value
                            directly, without any conversion at all.

                            Air-Code (finger's crossed)

                            Dim SomeTimeSoon as New DateTime
                            SomeTimeSoon = DateTimePicker1 .Value
                            MessageBox.Show ( SomeTimeSoon.To String() )

                            HTH,
                            Phill W.


                            Comment

                            • Herfried K. Wagner [MVP]

                              #15
                              Re: Convert to date

                              * "simon" <simon.zupan@st ud-moderna.si> scripsit:[color=blue]
                              > I read a value from timePicker and it is:
                              >
                              > start="12/18/2003 11:52:28 AM" String[/color]

                              Why not use the 'Value' directly?

                              --
                              Herfried K. Wagner [MVP]
                              <http://www.mvps.org/dotnet>

                              Comment

                              Working...