Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Convert string to datetime

Convert string to datetime

Scheduled Pinned Locked Moved C#
questionhelp
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    treuveni
    wrote on last edited by
    #1

    Hi, I have a string with the format yyyymmdd. I'm trying to convert it to date time by DateTime.Parse(myString), but i'm getting an error. How can i convert it?

    E G V 3 Replies Last reply
    0
    • T treuveni

      Hi, I have a string with the format yyyymmdd. I'm trying to convert it to date time by DateTime.Parse(myString), but i'm getting an error. How can i convert it?

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      DateTime.ParseExact("20011215", "yyyyMMdd"); //note the capital M's

      Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

      T 1 Reply Last reply
      0
      • E Ennis Ray Lynch Jr

        DateTime.ParseExact("20011215", "yyyyMMdd"); //note the capital M's

        Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

        T Offline
        T Offline
        treuveni
        wrote on last edited by
        #3

        Ennis Ray Lynch, Jr. wrote:

        DateTime.ParseExact("20011215", "yyyyMMdd"); //note the capital M's

        What about the IFormatProvider at the constructor? There is no constructor at the ParseExact that takes 2 parameters

        modified on Wednesday, June 15, 2011 3:37 PM

        A 1 Reply Last reply
        0
        • T treuveni

          Ennis Ray Lynch, Jr. wrote:

          DateTime.ParseExact("20011215", "yyyyMMdd"); //note the capital M's

          What about the IFormatProvider at the constructor? There is no constructor at the ParseExact that takes 2 parameters

          modified on Wednesday, June 15, 2011 3:37 PM

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #4

          DateTime d = DateTime.ParseExact("20011215", "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);

          Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.

          T 1 Reply Last reply
          0
          • A AspDotNetDev

            DateTime d = DateTime.ParseExact("20011215", "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);

            Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.

            T Offline
            T Offline
            treuveni
            wrote on last edited by
            #5

            10x :-D

            1 Reply Last reply
            0
            • T treuveni

              Hi, I have a string with the format yyyymmdd. I'm trying to convert it to date time by DateTime.Parse(myString), but i'm getting an error. How can i convert it?

              G Offline
              G Offline
              GenJerDan
              wrote on last edited by
              #6

              In addition to the other answers, there is also Convert.ToDateTime(something) Always nice to know different methods of doing something.

              Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life. My Mu[sic] My Films My Windows Programs, etc.

              A 1 Reply Last reply
              0
              • G GenJerDan

                In addition to the other answers, there is also Convert.ToDateTime(something) Always nice to know different methods of doing something.

                Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life. My Mu[sic] My Films My Windows Programs, etc.

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #7

                That would not help in this case.

                Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.

                G 1 Reply Last reply
                0
                • T treuveni

                  Hi, I have a string with the format yyyymmdd. I'm trying to convert it to date time by DateTime.Parse(myString), but i'm getting an error. How can i convert it?

                  V Offline
                  V Offline
                  V 0
                  wrote on last edited by
                  #8

                  1. What is the error it gives you 2. Use the TryParseExact function. 3. Read up on MSDN for the format string options[^] Hope this helps.

                  V.

                  1 Reply Last reply
                  0
                  • A AspDotNetDev

                    That would not help in this case.

                    Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.

                    G Offline
                    G Offline
                    GenJerDan
                    wrote on last edited by
                    #9

                    Probably not, but I don't know all the possible Culture formats available. There might be one out there who decided to use sensible dates.

                    Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life. My Mu[sic] My Films My Windows Programs, etc.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups