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. Database & SysAdmin
  3. Database
  4. sql Date conversion not working in sql 2000

sql Date conversion not working in sql 2000

Scheduled Pinned Locked Moved Database
database
9 Posts 8 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.
  • R Offline
    R Offline
    Robymon
    wrote on last edited by
    #1

    I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.

    B C L L P 6 Replies Last reply
    0
    • R Robymon

      I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.

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

      Use a parameterized query, that will do the magic around the date format.

      1 Reply Last reply
      0
      • R Robymon

        I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.

        C Offline
        C Offline
        Corporal Agarn
        wrote on last edited by
        #3

        It is based on how the systems are setup. Cannot remember the SET command and have to go to work. Sorry.

        S 1 Reply Last reply
        0
        • R Robymon

          I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Your string-representation is a culture-dependent format, a way of displaying a date in a specific culture. Date (and time) itself is not a string, but a number. Make sure it's a DATE column in the database, and pass a Date (not a string) to the query. Use parameters as suggested.

          using (var con = new SqlConnection(connectionString))
          using (var cmd = con.CreateCommand())
          {
          cmd.CommandText = "SELECT * FROM SomeTable WHERE MyDate = @MyDate";
          cmd.Parameters.AddWithValue("@MyDate", DateTime.Now);
          }

          Bastard Programmer from Hell :suss:

          1 Reply Last reply
          0
          • R Robymon

            I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.

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

            the purpose of a database is to store information, not to format it. Store dates and datetimes in fields with the appropriate type, and let your applications take care of formatting when presenting results to the user. Do not try and have the database format stuff, you will get lots of trouble and never get satisfactory results. And as others have said, use SQL parameters rather than SQL string concatenation, to feed dates and datetimes to the database; thus avoiding all conflicts with regional settings and the like. :)

            Luc Pattyn [My Articles] Nil Volentibus Arduum

            1 Reply Last reply
            0
            • R Robymon

              I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.

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

              If the column is a DATETIME, then the statement "it is saving as MM/DD/YYYY format" is untrue. If the output of SELECT thedate FROM table shows different formats when executed on different systems, it is because of the "Region and Language" settings of the systems -- see the control panel -- and this is correct behaviour. If you want to override this behaviour (you shouldn't) then format it via the query. And I strongly reccommend ISO 8601 format YYYY-MM-DD.

              1 Reply Last reply
              0
              • C Corporal Agarn

                It is based on how the systems are setup. Cannot remember the SET command and have to go to work. Sorry.

                S Offline
                S Offline
                Simon_Whale
                wrote on last edited by
                #7

                SET DATEFORMAT DMY

                that the one you were thinking of?

                Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

                C 1 Reply Last reply
                0
                • S Simon_Whale

                  SET DATEFORMAT DMY

                  that the one you were thinking of?

                  Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

                  C Offline
                  C Offline
                  Corporal Agarn
                  wrote on last edited by
                  #8

                  Yep thanks

                  1 Reply Last reply
                  0
                  • R Robymon

                    I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.

                    V Offline
                    V Offline
                    vvashishta
                    wrote on last edited by
                    #9

                    Put it like, CONVERT( VARCHAR, @To AS DATETIME, 103 ) ) - Happy Coding - Vishal Vashishta

                    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