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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Entering the current date and time into a sql server database

  • 02-03-2006 4: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, Registered Users 2 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