Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding current date time in SQL Table using SSMS Edit Mode

Tags:

sql

sql-server

How can I add the current date time to a SQL table in edit mode?

That is, in MS SQL, when you do right click on a table and click on Edit Top 200 Rows. I would like to fill current date time in the cell.

GETDATE() or CURRENT_TIMESTAMP does not work.

like image 498
blue piranha Avatar asked Sep 16 '16 17:09

blue piranha


People also ask

How can I insert current date and time in a table in SQL?

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 get today's date in SSMS?

SQL Server GETDATE() Function The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss.


2 Answers

Here's something fairly quick and easy.

In a new query window execute the query, SELECT GETDATE().

Select the result in the result pane and ctrl-c to copy it to the clipboard.

Then go back to your Edit window, and paste into the datetime cell(s).

like image 194
Tab Alleman Avatar answered Sep 19 '22 08:09

Tab Alleman


You can't manually call GETDATE() in edit mode. Instead, add GETDATE() as the default value for the column in design mode, and refrain from adding a value to the column in edit mode. Then SQL Server will add the current date-time as the value.

like image 24
Chamika Goonetilaka Avatar answered Sep 18 '22 08:09

Chamika Goonetilaka