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. stored procedure and date format

stored procedure and date format

Scheduled Pinned Locked Moved Database
databasehelpsql-serversysadminquestion
4 Posts 4 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.
  • U Offline
    U Offline
    User 446798
    wrote on last edited by
    #1

    hi I m passing the date parameter to a stored procedure. The stored procedure not does not accept the date format as 'dd/mm/yyyy'. It gives an error -"error converting data type varchar to datetime". My machine's regional setting is set to 'UK' i.e. "dd/mm/yyyy". How can i make a change in SQL server so that it accepts date parameters in the "dd/mm/yyyy". please help shelly

    R M F 3 Replies Last reply
    0
    • U User 446798

      hi I m passing the date parameter to a stored procedure. The stored procedure not does not accept the date format as 'dd/mm/yyyy'. It gives an error -"error converting data type varchar to datetime". My machine's regional setting is set to 'UK' i.e. "dd/mm/yyyy". How can i make a change in SQL server so that it accepts date parameters in the "dd/mm/yyyy". please help shelly

      R Offline
      R Offline
      Raven123
      wrote on last edited by
      #2

      SET DATEFORMAT dmy

      1 Reply Last reply
      0
      • U User 446798

        hi I m passing the date parameter to a stored procedure. The stored procedure not does not accept the date format as 'dd/mm/yyyy'. It gives an error -"error converting data type varchar to datetime". My machine's regional setting is set to 'UK' i.e. "dd/mm/yyyy". How can i make a change in SQL server so that it accepts date parameters in the "dd/mm/yyyy". please help shelly

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        1. Don't concatenate parameters in your command string - use a SqlParameter object (ADO.NET) or the Parameters collection of the Command object (ADO). 2. If you must use a literal date, use the ISO format 'yyyymmdd'. SQL Server will always accept this format, regardless of locale settings. Stability. What an interesting concept. -- Chris Maunder

        1 Reply Last reply
        0
        • U User 446798

          hi I m passing the date parameter to a stored procedure. The stored procedure not does not accept the date format as 'dd/mm/yyyy'. It gives an error -"error converting data type varchar to datetime". My machine's regional setting is set to 'UK' i.e. "dd/mm/yyyy". How can i make a change in SQL server so that it accepts date parameters in the "dd/mm/yyyy". please help shelly

          F Offline
          F Offline
          Frank Kerrigan
          wrote on last edited by
          #4

          I never pass any dates to a SQL server I always pass DD MM YY then build the date on the fly in the SQL server Strored Proc. Example below. ########################################################################################### CREATE PROCEDURE usp_myproc @YearInt int, @MonthInt int, @DayInt int AS DECLARE @CD_DATE datetime DECLARE @TempVarChar varchar(50) Set @TempVarChar = CAST(@DayInt As Varchar(2) ) + '/' + CAST(@MonthInt As Varchar(2) ) + '/' + CAST(@YearInt As Varchar(4) ) Set @CD_DATE = (Convert( datetime, @TempVarChar, 103 )) SELECT @CD_DATE go

          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