Update date field in SQL Server (2023)

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.

Download TablePlus for Mac.

Not on Mac? Download TablePlus for Windows.

On Linux? Download TablePlus for Linux

Need a quick edit on the go? Download TablePlus for iOS

Update date field in SQL Server (1)

Top Articles
Latest Posts
Article information

Author: Trent Wehner

Last Updated: 24/12/2023

Views: 6151

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Trent Wehner

Birthday: 1993-03-14

Address: 872 Kevin Squares, New Codyville, AK 01785-0416

Phone: +18698800304764

Job: Senior Farming Developer

Hobby: Paintball, Calligraphy, Hunting, Flying disc, Lapidary, Rafting, Inline skating

Introduction: My name is Trent Wehner, I am a talented, brainy, zealous, light, funny, gleaming, attractive person who loves writing and wants to share my knowledge and understanding with you.