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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Changing date format

Changing date format

Scheduled Pinned Locked Moved C#
databasecomtutorial
10 Posts 6 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.
  • P Offline
    P Offline
    pmartike
    wrote on last edited by
    #1

    Hi! I'm working with Microsoft SQL Database. X| Anybody knows how to change date format form code: Now it's MM/DD/YYYY but i want DD/MM/YYYY. :(( Thank you.:rose:

    -------------------------------- visit: http://pmartike.deviantart.com/

    M H M P 4 Replies Last reply
    0
    • P pmartike

      Hi! I'm working with Microsoft SQL Database. X| Anybody knows how to change date format form code: Now it's MM/DD/YYYY but i want DD/MM/YYYY. :(( Thank you.:rose:

      -------------------------------- visit: http://pmartike.deviantart.com/

      M Offline
      M Offline
      Muhammad Gouda
      wrote on last edited by
      #2

      I am familier with MS Access rather than SQL And to do that there, I choose my format in the database designe phase (Set the date field format to whatever you want). and do not need coding for this. I think SQL Server provides same thing

      Mohamed Gouda Egypt

      1 Reply Last reply
      0
      • P pmartike

        Hi! I'm working with Microsoft SQL Database. X| Anybody knows how to change date format form code: Now it's MM/DD/YYYY but i want DD/MM/YYYY. :(( Thank you.:rose:

        -------------------------------- visit: http://pmartike.deviantart.com/

        H Offline
        H Offline
        Harini N K
        wrote on last edited by
        #3

        Hi Use SET DATEFORMAT See the example below: **Example 1 :** executes without any error use northwind go set dateformat dmy go select top 10 * from Orders where requireddate >= '15-08-1996' **Example 2 :** gives error use northwind go set dateformat mdy go select top 10 * from Orders where requireddate >= '15-08-1996'

        Harini

        P 1 Reply Last reply
        0
        • H Harini N K

          Hi Use SET DATEFORMAT See the example below: **Example 1 :** executes without any error use northwind go set dateformat dmy go select top 10 * from Orders where requireddate >= '15-08-1996' **Example 2 :** gives error use northwind go set dateformat mdy go select top 10 * from Orders where requireddate >= '15-08-1996'

          Harini

          P Offline
          P Offline
          pmartike
          wrote on last edited by
          #4

          And this works from code in .NET? Thanks anyway! ;)

          -------------------------------- visit: http://pmartike.deviantart.com/

          1 Reply Last reply
          0
          • P pmartike

            Hi! I'm working with Microsoft SQL Database. X| Anybody knows how to change date format form code: Now it's MM/DD/YYYY but i want DD/MM/YYYY. :(( Thank you.:rose:

            -------------------------------- visit: http://pmartike.deviantart.com/

            M Offline
            M Offline
            Md Mustafa
            wrote on last edited by
            #5

            just type cast datetimr to string and give parameter as your desire format like:- .ToString("dd/mm/yyyy");

            Mohammad Mustafa

            P 1 Reply Last reply
            0
            • M Md Mustafa

              just type cast datetimr to string and give parameter as your desire format like:- .ToString("dd/mm/yyyy");

              Mohammad Mustafa

              P Offline
              P Offline
              pmartike
              wrote on last edited by
              #6

              this returns me a string like this: "10/46/2007" if i used for today's date.. :omg:

              -------------------------------- visit: http://pmartike.deviantart.com/

              V 1 Reply Last reply
              0
              • P pmartike

                this returns me a string like this: "10/46/2007" if i used for today's date.. :omg:

                -------------------------------- visit: http://pmartike.deviantart.com/

                V Offline
                V Offline
                Vikram A Punathambekar
                wrote on last edited by
                #7

                mm represents minutes. Use MM for the month.

                Cheers, Vıkram.


                After all is said and done, much is said and little is done.

                P 1 Reply Last reply
                0
                • V Vikram A Punathambekar

                  mm represents minutes. Use MM for the month.

                  Cheers, Vıkram.


                  After all is said and done, much is said and little is done.

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

                  thanks :-D

                  -------------------------------- visit: http://pmartike.deviantart.com/

                  1 Reply Last reply
                  0
                  • P pmartike

                    Hi! I'm working with Microsoft SQL Database. X| Anybody knows how to change date format form code: Now it's MM/DD/YYYY but i want DD/MM/YYYY. :(( Thank you.:rose:

                    -------------------------------- visit: http://pmartike.deviantart.com/

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

                    Please consider using an ISO 8601 compliant format -- .ToString ( "yyyy-MM-dd" )

                    P 1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      Please consider using an ISO 8601 compliant format -- .ToString ( "yyyy-MM-dd" )

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

                      Thanks! Problem solved :D

                      -------------------------------- visit: http://pmartike.deviantart.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