Ujjwal Vaish Ujjwal Vaish - 2 months ago 7
SQL Question

change only the month of a date in sql

i have a column

readiness_dt
which is a date in
mm/dd/yyyy
.I want to update the month of this date to the value present in another column
month
. Is there a query to just modify the month for a date.

E.g. readiness_dt month
02/14/2013 06

I want a function which should change the readiness_dt to 06/14/2013

hsd hsd
Answer

This should work:

SELECT DATEADD (month, 'your column name from 
      another table','xx/xx/xxxx') 
from 'your other table'

Example:

    create table date_test(
    interval int)

    insert into date_test values (1)

    insert into date_test values (2)

    insert into date_test values (3)

    select * from date_test

    select GETDATE() as Cur_date, DATEADD(month,interval,GETDATE()) as Interval_Added     

    from date_test

Please check this as well

Is it possible to use values from another table as the interval in a DATEADD function?