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. Date Format

Date Format

Scheduled Pinned Locked Moved C#
csharpdatabasesql-servervisual-studiosysadmin
13 Posts 6 Posters 1 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.
  • M Offline
    M Offline
    mjawadkhatri
    wrote on last edited by
    #1

    How to change date format in c# i need dd/mm/yy i am using Vs 2008 And SQL Server 2005 Please Help Me thanks in advance

    P P 2 Replies Last reply
    0
    • M mjawadkhatri

      How to change date format in c# i need dd/mm/yy i am using Vs 2008 And SQL Server 2005 Please Help Me thanks in advance

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You'll be pleased to know that there are several handy formatters available for dates. This one could be achieved using something like:

      Console.WriteLine("Date is {0}", DateTime.Now.ToString("dd/MM/yy"));

      Why do you need to change the date format though? It's generally better to leave the date formats as the user expects them to be set up based on their locale settings. Changing them round may lead to unfortunate consequences for the user if they misread the date because of differences in the format.

      I'm not a stalker, I just know things. Oh by the way, you're out of milk.

      Forgive your enemies - it messes with their heads

      My blog | My articles | MoXAML PowerToys | Onyx

      M 1 Reply Last reply
      0
      • P Pete OHanlon

        You'll be pleased to know that there are several handy formatters available for dates. This one could be achieved using something like:

        Console.WriteLine("Date is {0}", DateTime.Now.ToString("dd/MM/yy"));

        Why do you need to change the date format though? It's generally better to leave the date formats as the user expects them to be set up based on their locale settings. Changing them round may lead to unfortunate consequences for the user if they misread the date because of differences in the format.

        I'm not a stalker, I just know things. Oh by the way, you're out of milk.

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Onyx

        M Offline
        M Offline
        mjawadkhatri
        wrote on last edited by
        #3

        i need to insert date in Sql Server 2005 as DD/MM/yy how i can do this?? please Tell Me Thanks In Advance

        L P 2 Replies Last reply
        0
        • M mjawadkhatri

          i need to insert date in Sql Server 2005 as DD/MM/yy how i can do this?? please Tell Me Thanks In Advance

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

          a database should store data using the most appropriate type; string is not the most appropriate type for datetimes, as it is subject to lots of confusion. Use an actual date or datetime field. BTW: you may be interested in reading this little article[^]. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

          M G 2 Replies Last reply
          0
          • M mjawadkhatri

            i need to insert date in Sql Server 2005 as DD/MM/yy how i can do this?? please Tell Me Thanks In Advance

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            You should never store the data in a format such as this. Store it in a locale agnostic fashion, and let the front end format the string to the relevant format using a method such as ToShortDateString() on a DateTime.

            I'm not a stalker, I just know things. Oh by the way, you're out of milk.

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Onyx

            1 Reply Last reply
            0
            • L Luc Pattyn

              a database should store data using the most appropriate type; string is not the most appropriate type for datetimes, as it is subject to lots of confusion. Use an actual date or datetime field. BTW: you may be interested in reading this little article[^]. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

              M Offline
              M Offline
              musefan
              wrote on last edited by
              #6

              Another Luc-ticle strikes again ;)

              return 5;

              L 1 Reply Last reply
              0
              • M musefan

                Another Luc-ticle strikes again ;)

                return 5;

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

                There must be a reason why I turned my answers to popular questions into little articles... :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                M 1 Reply Last reply
                0
                • L Luc Pattyn

                  There must be a reason why I turned my answers to popular questions into little articles... :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                  M Offline
                  M Offline
                  musefan
                  wrote on last edited by
                  #8

                  Because you know too much to fit into a reasonably sized forum post? :)

                  return 5;

                  L 1 Reply Last reply
                  0
                  • M musefan

                    Because you know too much to fit into a reasonably sized forum post? :)

                    return 5;

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

                    I also don't like typing the same things over and over too much. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                    1 Reply Last reply
                    0
                    • M mjawadkhatri

                      How to change date format in c# i need dd/mm/yy i am using Vs 2008 And SQL Server 2005 Please Help Me thanks in advance

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

                      You do that only when you output it, generally with ToString ( "format" ), or you could set the format of your system to do it -- I set mine to use an ISO 8601 format.

                      1 Reply Last reply
                      0
                      • L Luc Pattyn

                        a database should store data using the most appropriate type; string is not the most appropriate type for datetimes, as it is subject to lots of confusion. Use an actual date or datetime field. BTW: you may be interested in reading this little article[^]. :)

                        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

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

                        Unless you're using parameters to squirt the data into the database (as you should be doing), converting it to a string is necessary...and MS SQL expects a certain format (one of which is the one shown by the OP).

                        L 1 Reply Last reply
                        0
                        • G GenJerDan

                          Unless you're using parameters to squirt the data into the database (as you should be doing), converting it to a string is necessary...and MS SQL expects a certain format (one of which is the one shown by the OP).

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

                          is that any different from what my article says? :doh:

                          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                          G 1 Reply Last reply
                          0
                          • L Luc Pattyn

                            is that any different from what my article says? :doh:

                            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

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

                            Don't know. Didn't read it. Just responded to the post, not the btw. :laugh: OK. Just skimmed the article. Nope. Still, the OP just as likely did what I did, looked at the post itself which essentially said to redesign the database if it wasn't using datetimes.

                            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