I have a Stored Proc in SQL Server that I am working on updated and trying to come up with a way to change the year in a date (only the year).
Example: Date is 01/05/2010 and at selection, I need the date to 01/05/2017.
You could use datefromparts
, if your SQL Server version is >=2012
SELECT
CONVERT(VARCHAR(12),
DATEFROMPARTS(DATEPART(YEAR, GETDATE()),
DATEPART(MONTH, '01/05/2010'),
DATEPART(DAY, '01/05/2010')), 103)
要选择当前年份,
SELECT DateAdd(YEAR, YEAR(GETDATE())-YEAR(date_field), date_field) FROM TableName
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.