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. INSERT - Date/Time INTO SQL ??

INSERT - Date/Time INTO SQL ??

Scheduled Pinned Locked Moved Database
databasec++sql-servervisual-studiosysadmin
5 Posts 2 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.
  • F Offline
    F Offline
    Fritzables
    wrote on last edited by
    #1

    Hi All, I am an app in VS C++ 2005 that uses an SQL Server 2005 database. I am having trouble understanding how to enter a date into the database. The field data type is: smalldatetime. The date and time has been assigned to a string and would have a value like '30/05/2007 5:30PM' When I write the query like: INSERT INTO MyTable(Date) VALUES(MySTRING) I end up with an error and assume it's to do with the way O have formatted the string - am I on the right track ? Fritzables.

    W 1 Reply Last reply
    0
    • F Fritzables

      Hi All, I am an app in VS C++ 2005 that uses an SQL Server 2005 database. I am having trouble understanding how to enter a date into the database. The field data type is: smalldatetime. The date and time has been assigned to a string and would have a value like '30/05/2007 5:30PM' When I write the query like: INSERT INTO MyTable(Date) VALUES(MySTRING) I end up with an error and assume it's to do with the way O have formatted the string - am I on the right track ? Fritzables.

      W Offline
      W Offline
      WoutL
      wrote on last edited by
      #2

      Hi Fritzables, It is very difficult to say on which track you are, without knowing the error message. But I expect the problem is the date format. You can try two things: SET DATEFROMAT DMY Or you can format the string to: '2007-05-20 5:30PM' I hope this helps.

      Wout Louwers

      F 1 Reply Last reply
      0
      • W WoutL

        Hi Fritzables, It is very difficult to say on which track you are, without knowing the error message. But I expect the problem is the date format. You can try two things: SET DATEFROMAT DMY Or you can format the string to: '2007-05-20 5:30PM' I hope this helps.

        Wout Louwers

        F Offline
        F Offline
        Fritzables
        wrote on last edited by
        #3

        G'Day Wout, If I was to enter the sting at: 30/05/2007 5:30PM then the error message goes something like: syntax error near 5. Ok, so if I was to use the SET DATEFORMAT DMY, at what point would I define this - sorry for the stupid question. Regards Fritzables.

        W 1 Reply Last reply
        0
        • F Fritzables

          G'Day Wout, If I was to enter the sting at: 30/05/2007 5:30PM then the error message goes something like: syntax error near 5. Ok, so if I was to use the SET DATEFORMAT DMY, at what point would I define this - sorry for the stupid question. Regards Fritzables.

          W Offline
          W Offline
          WoutL
          wrote on last edited by
          #4

          Ah, the errormessage explains something. You should try: INSERT INTO MyTable(Date) VALUES('30/5/2007 5:30PM') I think you forgot the quotation marks. If that does not work you can try: SET DATEFORMAT dmy;INSERT INTO MyTable(Date) VALUES('30/5/2007 5:30PM')

          Wout Louwers

          F 1 Reply Last reply
          0
          • W WoutL

            Ah, the errormessage explains something. You should try: INSERT INTO MyTable(Date) VALUES('30/5/2007 5:30PM') I think you forgot the quotation marks. If that does not work you can try: SET DATEFORMAT dmy;INSERT INTO MyTable(Date) VALUES('30/5/2007 5:30PM')

            Wout Louwers

            F Offline
            F Offline
            Fritzables
            wrote on last edited by
            #5

            Wout - you're an absolute legend !!! Yea, it was the missing quotes that put all things back in order. Thanks a million. Fritzables.

            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