inserting string date and time into mssql database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kencana
    New Member
    • Nov 2006
    • 26

    inserting string date and time into mssql database

    Hi All,

    I have some problem in inserting date and time entered by user from the GUI into the form. Any idea on how this can be done?

    Thank you

    Regards,
    Kencana
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    How (in what format) does the user enter the date and the time?

    Ronald

    Comment

    • kencana
      New Member
      • Nov 2006
      • 26

      #3
      Hi,

      User will choose the date and time from the date time picker (javascript) and it is in yyyy/mm/dd hh:mm:ss
      Every time i try to insert it, it will insert different date and time into the database.
      I hope you can help me out

      Regards,
      Kencana

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        What is the correct date and time format of your MS SQL system?

        You must adhere to that standard or you can setup the language of the user which connects to the DB, so that datetime is excepted in the language you have set up.

        Ronald

        Comment

        • kencana
          New Member
          • Nov 2006
          • 26

          #5
          Hi,

          i realized that the datetime format in mssql is dd/mm/yyyy hh:mm:ss am/pm
          so I changed the input date time format and it still gave me no luck. it keep inserting 1/01/1900. Also, i tried to insert the date time value into the database manually by entering 17/02/2008 and it is accepted.
          Any idea on how to solve this?

          Thank you

          Regards,
          Kencana

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Then you must have an error in your input format of the date (time) in your code. Show the code for that particular INSERT. And do not forget to enclose it within the appropriate code tags!

            Ronald

            Comment

            • kencana
              New Member
              • Nov 2006
              • 26

              #7
              hi,

              the following are my inserting code:

              [PHP]
              $content = str_replace("'" , "''",$_POST['content']);
              $startDate = "17/02/2008 12:00:00 AM";
              $endDate = "17/02/2008 12:00:00 PM";

              $insertStatemen t = "INSERT ANNOUNCEMENT (content,startd ate,enddate,dat eupdated) VALUES('" . $content . "', $startDate,$end Date,getdate()) ";
              if (!mssql_query($ insertStatement ,$dbhandle))
              {
              echo "Failed due to ".mssql_error() ;
              die('Error: ' . mssql_error());
              }
              else
              {
              echo "success";
              }

              mssql_close($db handle);
              [/PHP]

              regards,
              Kencana

              Comment

              • kencana
                New Member
                • Nov 2006
                • 26

                #8
                Hi All,

                anybody has any idea on how to insert string date into mssql database?

                Thank you

                Regards,
                Kencana Kesuma

                Comment

                • TheServant
                  Recognized Expert Top Contributor
                  • Feb 2008
                  • 1168

                  #9
                  How about justs storing a time stamp (as an INT) in the data base and convert back to a date when you need to display it?

                  Comment

                  • kencana
                    New Member
                    • Nov 2006
                    • 26

                    #10
                    Hi,

                    Thanks for your reply, can you explain further on what you mean by the method you mentioned?

                    Thank you

                    Regards,
                    Kencana Kesuma

                    Comment

                    Working...