Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Entering the current date and time into a sql server database

Options
  • 02-03-2006 5:23pm
    #1
    Closed Accounts Posts: 29


    Hi I need to insert the current date and time in to a sql server database. I have cretaed a cell in the database called Tme with the data type smalldatetime. I am using the following INSERT command

    SqlDataSource1.SelectCommand = "INSERT INTO B_DB (Time) VALUES (System.DateTime.Now)";

    But it gives a run time error saying syntax error at ).

    So I tired the following " + System.DateTime.Now + " and no joy, I tired creating a sql parameter but it would not allow me to convert System.DateTime.Now to a string to pass it as a sql parameter.

    Any idea's and help would be great?


Comments

  • Registered Users Posts: 841 ✭✭✭Dr Pepper


    I don't know if this will work on the sql you are using, but I use mySQL and there is a simple NOW() function for getting the current datetime:

    INSERT INTO B_DB (Time) VALUES (NOW());

    Alternatively, perhaps the syntax: System.DateTime.Now() (with parentheses) would work.


  • Closed Accounts Posts: 3,357 ✭✭✭Beano


    if by sql server you mean Microsoft SQL server then just do

    INSERT INTO B_DB (Time) VALUES (getdate());


Advertisement