Update month/week only of date field

  • I have a field in a table that I want to update the month (and also the date in certain places).

    For example below I might want to change the month (03) to 05 or 06.

    2012-03-30 13:57:07.353

    Below I might want to change the day (25) to 18 or 19.

    2012-04-25 15:59:07.400

    Can anyone tell me how I might do this?

  • The best way would be to use DATEDIFF or DATEADD functions.

    So, if you want to change 2012-03-30 13:57:07.353 to 2012-05-30 13:57:07.353 you would do this:

    UPDATE tableA

    SET dateColumn = SELECT DATEADD(MONTH,2,dateColumn)

    WHERE idColumn = something

    Jared
    CE - Microsoft

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply