I have One Column in the Mytable called StockDate and its DataType is DateTime.
So My Table contains record as follows
SID StockDate
----- ------------
1 2011-10-02 09:44:41.170
2 2011-10-02 09:48:23.234
Here I want to update Only the Date of the StockDate as "2011-09-30". But the time should be same as it is. How to do this? Please I need all your suggestions.
We'll use the GETDATE() function to get the current date and time. Then we'll use the CAST() function to convert the returned datetime data type into a date data type.
To update with the current date and time: UPDATE table_name SET date_field = CURRENT_TIMESTAMP; To update with a specific date value: UPDATE table_name SET date_field = 'YYYY-MM-DD HH:MM:SS.
The UPDATE statement in SQL is used to update the data of an existing table in the database. We can update single columns as well as multiple columns using the UPDATE statements as per our requirement. With this article, we will learn how to Update the Date Field in SQL Server.
SQL FORMAT select * from Bookings where StartTime >= cast('2014-02-15' as date) and StartTime < cast('2014-02-14' as date); Show activity on this post. '2/15/2014' can be interpreted different depending on your locale. Try using the ISO date literal '2014-02-15', which is independent of the locale.
Work out the different in whole days and subtract that...
UPDATE
MyTable
SET
StockDate = DATEADD(day, DATEDIFF(day, StockDate, '20110930'), StockDate)
WHERE
...
Note the use of the yyyymmdd for SQL Server.
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