Friday, February 24, 2012

inserting the current date and time into SQL Server database

I need an SQL string that inserts the current date into a database.

So far I have tried:

SQL = "INSERT INTO X (START_DATE) VALUES('" & Date.Now &"')"

mycomm =

New SqlCommand(sql, myconn)

mycomm.ExecuteNonQuery()

However, there is a problem with the SQL command. The problem is related to the date. Is there a way of programatically inserting the current date/time into the SQL database? Language used is VB.

GetDate() is a function in SQL Server that returns the current timestamp. So you can directly use that.

SQL = "INSERT INTO X (START_DATE) VALUES( GetDate())"

No comments:

Post a Comment