I have a table with column ( dateDT), formatted as the date and time the variable ( @selYear) was input in my Select, formatted as int.
How can I replace the year in the date from my table with a variable input and return the result in the date and time format (within the selection)?
I tried the following, but this returns invalid dates / years:
CONVERT(DATETIME, (@selYear + MONTH(dateDT) + DAY(dateDT))) AS dateDT,
Example:
@selYear = 2014
dateDT = 2010-05-02 00:00:00.000
In this case, my result should be:
dateDT = 2014-05-02 00:00:00.000
source
share