Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you update a DateTime field in T-SQL?

The following query does not update the datetime field:

update table SET EndDate = '2009-05-25' WHERE Id = 1 

I also tried it with no dashes, but that does not work either.

like image 413
Xaisoft Avatar asked Jun 29 '10 19:06

Xaisoft


People also ask

How can update only date in datetime column of table in SQL Server?

Just use varchar and modify what you want in it without touch the time. In this example I use CONVERT(varchar(12), columnDatetime) to get a string with length of 12 characteres assuming a case of time with a format for example like "20:10:15.250".

How to update a date and time field in SQL?

If you want to update a date & time field in SQL, you should use the following query. let's see the syntax of sql update date. Firstly we take a table in which we want to update date and time fields. If you want to change the first row which id is 1 then you should write the following syntax:

How to update date of datetime field in MySQL using arithmetic operator?

Update date of datetime field with the help of arithmetic operator minus (-). The syntax is as follows update yourTableName set yourDateTimeColumnName=yourDateTimeColumnName - interval yourValue day where date (yourDateTimeColumnName)=’yourDateValue’; To understand the above syntax, let us create a table.

What is date format in SQL Server?

SQL Date Format Examples SQL Date Data Types SQL comes with the following data types for storing the date/time value in the database: DATE - format: YYYY-MM-DD

What are the different types of date in SQL Server?

SQL Date Data Types. SQL comes with the following data types for storing the date/time value in the database: DATE - format: YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS. TIMESTAMP - format: YYYY-MM-DD HH:MI:SS. YEAR - format YYYY or YY. Assume that we have the following ‘customers’ table:


1 Answers

When in doubt, be explicit about the data type conversion using CAST/CONVERT:

UPDATE TABLE    SET EndDate = CAST('2009-05-25' AS DATETIME)  WHERE Id = 1 
like image 130
OMG Ponies Avatar answered Sep 24 '22 02:09

OMG Ponies