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. Other Discussions
  3. The Weird and The Wonderful
  4. Format Date

Format Date

Scheduled Pinned Locked Moved The Weird and The Wonderful
ruby
6 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.
  • B Offline
    B Offline
    Bernhard Hiller
    wrote on last edited by
    #1

    Doing some maintenance on an application which I developed a few years ago, I found a small gem:

        public string formatDateMySQL(DateTime date)
        {
            StringBuilder strTmp = new StringBuilder(date.Year.ToString());
            strTmp.Append("-");
            strTmp.Append(date.Month.ToString());
            strTmp.Append("-");
            strTmp.Append(date.Day.ToString());
    
            return strTmp.ToString();
        }
    

    Yeah, formatting DateTime values works different everywhere, and that's a very "clever" way of coping with that... License: You may use this code according to the CodeProject license. :)

    P E S 3 Replies Last reply
    0
    • B Bernhard Hiller

      Doing some maintenance on an application which I developed a few years ago, I found a small gem:

          public string formatDateMySQL(DateTime date)
          {
              StringBuilder strTmp = new StringBuilder(date.Year.ToString());
              strTmp.Append("-");
              strTmp.Append(date.Month.ToString());
              strTmp.Append("-");
              strTmp.Append(date.Day.ToString());
      
              return strTmp.ToString();
          }
      

      Yeah, formatting DateTime values works different everywhere, and that's a very "clever" way of coping with that... License: You may use this code according to the CodeProject license. :)

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Shirley AppendFormat is the way to go. :laugh:

      L 1 Reply Last reply
      0
      • P PIEBALDconsult

        Shirley AppendFormat is the way to go. :laugh:

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        No, but ISO-8601 is IIRC. :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        1 Reply Last reply
        0
        • B Bernhard Hiller

          Doing some maintenance on an application which I developed a few years ago, I found a small gem:

              public string formatDateMySQL(DateTime date)
              {
                  StringBuilder strTmp = new StringBuilder(date.Year.ToString());
                  strTmp.Append("-");
                  strTmp.Append(date.Month.ToString());
                  strTmp.Append("-");
                  strTmp.Append(date.Day.ToString());
          
                  return strTmp.ToString();
              }
          

          Yeah, formatting DateTime values works different everywhere, and that's a very "clever" way of coping with that... License: You may use this code according to the CodeProject license. :)

          E Offline
          E Offline
          ekolis
          wrote on last edited by
          #4

          Bernhard Hiller wrote:

          License: You may use this code according to the CodeProject license. :)

          Don't you mean, "License: You must never use this code under penalty of tar-and-feathering"? :)

          B 1 Reply Last reply
          0
          • E ekolis

            Bernhard Hiller wrote:

            License: You may use this code according to the CodeProject license. :)

            Don't you mean, "License: You must never use this code under penalty of tar-and-feathering"? :)

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #5

            Just wait a little, and you'll see it becoming the solution for date/time formatting problems with MySQL server in Quick Answers...

            1 Reply Last reply
            0
            • B Bernhard Hiller

              Doing some maintenance on an application which I developed a few years ago, I found a small gem:

                  public string formatDateMySQL(DateTime date)
                  {
                      StringBuilder strTmp = new StringBuilder(date.Year.ToString());
                      strTmp.Append("-");
                      strTmp.Append(date.Month.ToString());
                      strTmp.Append("-");
                      strTmp.Append(date.Day.ToString());
              
                      return strTmp.ToString();
                  }
              

              Yeah, formatting DateTime values works different everywhere, and that's a very "clever" way of coping with that... License: You may use this code according to the CodeProject license. :)

              S Offline
              S Offline
              S 53K S
              wrote on last edited by
              #6

              Is this written in C#? :confused: I guess the more simpler way would be. date.ToString("yyyy-MM-dd") out puts the date as 2012-04-18 or date.ToString("yyyy-M-dd") out puts the date as 2012-4-18 If not C# Kudos to you ;)

              Sastry

              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