Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do an insert with DATETIME now inside of SQL server mgmt studio

I have a website that does inserts into this table below. I need to do some manual inserts but I wasn't sure how do pass in the equivalent of DateTime.Now in C#.

I am running this below from the query editor in SQL server mgmt studio. Is there any way to pass in the current date time in this query below.

INSERT INTO [Business]            ([IsDeleted]            ,[FirstName]            ,[LastName]            ,[LastUpdated]            ,[LastUpdatedBy])      VALUES            (0, 'Joe', 'Thomas',             ,<LastUpdated, datetime,>            ,<LastUpdatedBy, nvarchar(50),>) 
like image 629
leora Avatar asked Jun 18 '10 18:06

leora


People also ask

How can I insert current date and time in SQL Server?

The simplest method to insert the current date and time in MySQL is to use the now() function. Once you call the function, it returns the current date and time in the system's configured time zone as a string. The value returned from the now() function is YYYY-MM-DD for the date and HH-MM-SS-UU for the time record.

How do I insert the current date automatically in SQL?

You can use now() with default auto fill and current date and time for this. Later, you can extract the date part using date() function. Let us set the default value with some date.


2 Answers

Use CURRENT_TIMESTAMP (or GETDATE() on archaic versions of SQL Server).

like image 99
Craig Stuntz Avatar answered Oct 04 '22 19:10

Craig Stuntz


Just use GETDATE() or GETUTCDATE() (if you want to get the "universal" UTC time, instead of your local server's time-zone related time).

INSERT INTO [Business]            ([IsDeleted]            ,[FirstName]            ,[LastName]            ,[LastUpdated]            ,[LastUpdatedBy])      VALUES            (0, 'Joe', 'Thomas',             GETDATE(),  <LastUpdatedBy, nvarchar(50),>) 
like image 37
marc_s Avatar answered Oct 04 '22 20:10

marc_s