Well, I've found some content on the Internet, and we've integrated some of the built-in methods of SQL Server
The first is the Convert method: https://msdn.microsoft.com/zh-cn/library/ms187928.aspx
CONVERT (data_type (length),data_to_be_converted,style)
This method is equivalent to formatting the date data into a string output.
And then the stuff method: https://msdn.microsoft.com/zh-cn/library/ms188043.aspx
STUFF (character_expression, start, length, replacewith_expression)
This method removes the specified length of characters from the beginning of the first string, and then inserts the second string at the beginning of the first string.
That would be a good local replacement.
Test:
select top 1 addtime, convert ( nvarchar (23 ), Addtime,121 ), stuff (convert (nvarchar (23 ), Addtime,121 ), 1 , 4 , '
Well, it seems to be pretty good.
Here are the original posts: http://blog.csdn.net/yangbolg/article/details/18596311
--Modify the year of the D table Date field
Update D
Set Birth=stuff (convert (nvarchar, birth,120), 1, 4, ' 2012 ')
--Modify the month of the D table Date field
Update D
Set Birth=stuff (convert (nvarchar, birth,120), 6, 2, ' 3 ')
--Change the number of days in the D Table Date field
Update D
Set Birth=stuff (convert (nvarchar, birth,120), 9, 2, ' 25 ')
--Change the number of hours in the D Table Date field
Update D
Set Birth =stuff (convert (nvarchar, birth,120), 12, 2, ' 9 ')
--Change the number of minutes in the D Table Date field
Update D
Set Birth =stuff (convert (nvarchar, birth,120), 15, 2, ' 15 ')
--Modify the number of seconds in the D Table Date field
Update D
Set Birth =stuff (convert (nvarchar, birth,120), 18, 2, ' 30 ')
--Modify the year, hour of the D table Date field
Update D
Set Birth=convert (Datetime,stuff (Stuff (Convert (char,birth,120), 1, 4, ' 2011 '), 12, 2, ' 02 '))
--Modify the year of the table date field
Update D
Set Birth=dateadd (Year,datediff (Year,birth, ' 2016-01-01 '), birth)
Where year (birth) <>2012
--Modify the hour of the table date field
Update D
Set Birth=dateadd (Hour,3,birth)
How do I update part of the data in a Date field in a database using T-SQL (year? Month? Day? When Score of Seconds? )