views:

23

answers:

2

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 anyway 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),>)
+2  A: 

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

Craig Stuntz
"This function is the ANSI SQL equivalent to GETDATE." It's non-ANSI, not prehistoric
gbn
I can't think of a good reason to write non-standard SQL when the standard version works just as well.
Craig Stuntz
+1  A: 

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),>)
marc_s