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. Database & SysAdmin
  3. Database
  4. Writing Date back to SQL Anywhere DB - Exception Thrown

Writing Date back to SQL Anywhere DB - Exception Thrown

Scheduled Pinned Locked Moved Database
databasehelp
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.
  • M Offline
    M Offline
    MWRivera
    wrote on last edited by
    #1

    Hi there, I have a text field that I've stored a date pulled from a SQL Anywhere DB. It displays fine, the problem I'm having is writing the date back to the database from the same text field, I recieve the following exception message: "iAnywhere.Data.SQLAnywhere.SAException: Cannot convert 1/1/1982 12:00:00 AM to a timestamp at ..." The field that I'm trying to write back to in the SQL Anywhere database is of type 'Date'. Really I only want to write the date portion of the DateTime back to the database. Hope you can help

    L 1 Reply Last reply
    0
    • M MWRivera

      Hi there, I have a text field that I've stored a date pulled from a SQL Anywhere DB. It displays fine, the problem I'm having is writing the date back to the database from the same text field, I recieve the following exception message: "iAnywhere.Data.SQLAnywhere.SAException: Cannot convert 1/1/1982 12:00:00 AM to a timestamp at ..." The field that I'm trying to write back to in the SQL Anywhere database is of type 'Date'. Really I only want to write the date portion of the DateTime back to the database. Hope you can help

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

      You need to put the date into a format that SQL recognises and can convert back to a proper DateTime type. I don't know about Anywhere DB but most systems would handle this OK.

      txtspeak is the realm of 9 year old children, not developers. Christian Graus

      M 1 Reply Last reply
      0
      • L Lost User

        You need to put the date into a format that SQL recognises and can convert back to a proper DateTime type. I don't know about Anywhere DB but most systems would handle this OK.

        txtspeak is the realm of 9 year old children, not developers. Christian Graus

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

        Thanks for the feedback Richard. I understand that the problem is caused by the format of the data being passed back into the database. I have the format as yyyy-MM-dd as this is the format of the existing dates in the database so I know the filed accepts or should accept this format. Has anyone ever used the built-in ASP.Net calendar to populate a text field and in turn a database date field? I think this is the way I'm going to go, with a button beside the text box to disply the calendar. If you know of any examples or have tried it yourself I would be more than greatful for links etc. Thanks

        L M 2 Replies Last reply
        0
        • M MWRivera

          Thanks for the feedback Richard. I understand that the problem is caused by the format of the data being passed back into the database. I have the format as yyyy-MM-dd as this is the format of the existing dates in the database so I know the filed accepts or should accept this format. Has anyone ever used the built-in ASP.Net calendar to populate a text field and in turn a database date field? I think this is the way I'm going to go, with a button beside the text box to disply the calendar. If you know of any examples or have tried it yourself I would be more than greatful for links etc. Thanks

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

          MWRivera wrote:

          I have the format as yyyy-MM-dd as this is the format of the existing dates in the database

          Unless you are storing your dates as strings then this is not the case. Dates in databases should always be stored as DateTime types which is the UTC value of the date and time. It is only when you need to display them that the actual formatting takes place, when it should be in accordance with your regional settings.

          txtspeak is the realm of 9 year old children, not developers. Christian Graus

          1 Reply Last reply
          0
          • M MWRivera

            Thanks for the feedback Richard. I understand that the problem is caused by the format of the data being passed back into the database. I have the format as yyyy-MM-dd as this is the format of the existing dates in the database so I know the filed accepts or should accept this format. Has anyone ever used the built-in ASP.Net calendar to populate a text field and in turn a database date field? I think this is the way I'm going to go, with a button beside the text box to disply the calendar. If you know of any examples or have tried it yourself I would be more than greatful for links etc. Thanks

            M Offline
            M Offline
            MWRivera
            wrote on last edited by
            #5

            Thanks guys. Thanks I managed to get the date saved in the following format yyyy-MM-dd and when the field is empty I simply insert NULL into the date field, which is accepted with no exception thrown.

            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