sql - Replace year in datetime date -
I have a table with the column ( dateDT
), which is based on date time and one variable Formatted in the form of my year in the form ( @selYear
), formatted as int.
How can I change the variable input from my table within a date of the year and convert the result into a one time format?
I have tried the following dates incorrect dates / year:
Convert (DATETIME, (SSLEER + MNST (DDT) + DAY (DDDT )) DTT as the date,
Example:
@selYear = 2014 dateDT = 2010-05-02 00: 00: 00.000
In this case, my result should be:
dateDT = 2014-05-02 00: A solution using the function:
DECLARE @selYear VARCHAR (4) = 2014 DECLARE @dateDT DATETI ME = '2010-05-02 00: 00: 00.000' SELECT DATEADD (YEAR, @ selYear - YEAR (@dateDT), @ dateDT)
with this small Example is the current year:
DECLARE @selYear INT = 200 9 DECLARE @dateDT DATETIME = '2010-05-02 00: 00: 00.000' Selection Date ADD (YEAR, @ selYear - YEAR ( @dateDT), @ dateDT)
Comments
Post a Comment