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. DateTime to yyyy\MM\dd conversion

DateTime to yyyy\MM\dd conversion

Scheduled Pinned Locked Moved C#
tutorialquestion
14 Posts 7 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.
  • C Chesnokov Yuriy

    How to convert with DateTime.ToString() method given date to yyyy\MM\dd format? e.g. "2011\06\17" I would not like to use String.Format(@"{0:D4}\{1:D2}\{2:D2}")

    Чесноков

    B Offline
    B Offline
    Blue_Boy
    wrote on last edited by
    #5

    You can try this string dateformat = DateTime.Now.ToString(@"yyyy\\MM\\dd").Replace("\\",@"\");


    I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

    G 1 Reply Last reply
    0
    • B Blue_Boy

      You can try this string dateformat = DateTime.Now.ToString(@"yyyy\\MM\\dd").Replace("\\",@"\");


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

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

      The .Replace is bothering me because "\\" is the same as @"\". Maybe you meant @"\\" instead of "\\".

      B 1 Reply Last reply
      0
      • G Groulien

        The .Replace is bothering me because "\\" is the same as @"\". Maybe you meant @"\\" instead of "\\".

        B Offline
        B Offline
        Blue_Boy
        wrote on last edited by
        #7

        I released that isn't necessary to use Replace so just using @"yyyy\\MM\\dd" will give correct format 2011\06\17 Thanks for correcting me :)


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

        modified on Friday, June 17, 2011 6:07 AM

        C 1 Reply Last reply
        0
        • C Chesnokov Yuriy

          How to convert with DateTime.ToString() method given date to yyyy\MM\dd format? e.g. "2011\06\17" I would not like to use String.Format(@"{0:D4}\{1:D2}\{2:D2}")

          Чесноков

          P Offline
          P Offline
          Prasanta_Prince
          wrote on last edited by
          #8

          Good answer BlueBoy..

          B 1 Reply Last reply
          0
          • B Blue_Boy

            Eraser_stp wrote:

            DateTime.ToString(@"yyyy\MM\dd");

            This code will not work. If you have this string date = DateTime.Now.ToString(@"yyyy\MM\dd"); again wrong format because you will get this result 2011M6d17


            I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

            E Offline
            E Offline
            Eraser_stp
            wrote on last edited by
            #9

            My bad. Thanks for pointing and correct answer. :)

            1 Reply Last reply
            0
            • C Chesnokov Yuriy

              How to convert with DateTime.ToString() method given date to yyyy\MM\dd format? e.g. "2011\06\17" I would not like to use String.Format(@"{0:D4}\{1:D2}\{2:D2}")

              Чесноков

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #10

              To back up the previous answers, there is a list of the formats available here: Formatting a DateTime for display - format string description[^]

              Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              B 1 Reply Last reply
              0
              • B Blue_Boy

                I released that isn't necessary to use Replace so just using @"yyyy\\MM\\dd" will give correct format 2011\06\17 Thanks for correcting me :)


                I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

                modified on Friday, June 17, 2011 6:07 AM

                C Offline
                C Offline
                Chesnokov Yuriy
                wrote on last edited by
                #11

                yes, thanks, that one works

                Чесноков

                B 1 Reply Last reply
                0
                • P Prasanta_Prince

                  Good answer BlueBoy..

                  B Offline
                  B Offline
                  Blue_Boy
                  wrote on last edited by
                  #12

                  Thanks :)


                  I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

                  1 Reply Last reply
                  0
                  • C Chesnokov Yuriy

                    yes, thanks, that one works

                    Чесноков

                    B Offline
                    B Offline
                    Blue_Boy
                    wrote on last edited by
                    #13

                    No problem. :)


                    I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

                    1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      To back up the previous answers, there is a list of the formats available here: Formatting a DateTime for display - format string description[^]

                      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

                      B Offline
                      B Offline
                      Blue_Boy
                      wrote on last edited by
                      #14

                      Good article :)


                      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

                      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