To update a date field with T-SQL, here is the general syntax:
UPDATE table_nameSETdate_field='date_value'[WHEREconditions];
To update with the current date:
UPDATE table_nameSET date_field = getdate();
To update with the current date and time:
UPDATE table_nameSET date_field = CURRENT_TIMESTAMP;
To update with a specific date value:
UPDATE table_nameSET date_field = 'YYYY-MM-DD HH:MM:SS.MMM';
When you update with a specific date value and not sure about the date format, use CAST
:
UPDATE table_nameSET date_field = CAST('date_value' AS DATETIME);
For example:
UPDATE studentSET registration_date = CAST('2019-09-25' AS DATETIME)WHERE id = 25;
Need a good GUI tool for databases? TablePlus provides a native client that allows you to access and manage Oracle, MySQL, SQL Server, PostgreSQL, and many other databases simultaneously using an intuitive and powerful graphical interface.
Not on Mac? Download TablePlus for Windows.
On Linux? Download TablePlus for Linux
Need a quick edit on the go? Download TablePlus for iOS