Ujjwal Vaish
Ujjwal Vaish

Reputation: 375

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

Upvotes: 1

Views: 8760

Answers (2)

hsd
hsd

Reputation: 56

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?

Upvotes: 0

Thanos Markou
Thanos Markou

Reputation: 2624

Try this:

SELECT DATEADD(month, 4, '02/14/2013 ')

Upvotes: 1

Related Questions