In the Microsoft SQL Server 2008 database, how can I insert both date and time in a datetime typed column, in a single command?
Asked
Active
Viewed 1.9k times
-2
-
possible duplicate of [Sql query to insert datetime in SQL Server](http://stackoverflow.com/questions/12957635/sql-query-to-insert-datetime-in-sql-server) – Dylan Corriveau May 12 '15 at 03:01
2 Answers
0
In MySQL you can use the function NOW() in MSSQL you can use the GETDATE() function. http://msdn.microsoft.com/en-us/library/ms188383.aspx
Here's an example :
INSERT INTO `table`(`datetime`) VALUES(GETDATE())

HerpaMoTeH
- 364
- 3
- 13
0
Specify the DATEFORMAT value for the current session, and use INSERT command to add new record, e.g.:
SET DATEFORMAT dmy;
INSERT INTO dbo.table1 VALUES (1, '24-07-2012 12:45:10')
SET DATEFORMAT mdy;
INSERT INTO dbo.table1 VALUES (2, '07-24-2012 12:45:10')

Devart
- 119,203
- 23
- 166
- 186