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.
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".
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:
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.
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
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With