Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Entering the current date and time into a sql server database

  • 02-03-2006 05: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: 821 ✭✭✭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