Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Location
    Ohio
    Posts
    20

    Question Unanswered: Convert a date function in SQL Server

    I have the date in the SQL server column as 2002-06-16 00:00:00.000 and I will be needing this to convert to 2003-06-16 00:00:00.000. Just the year from 2002 to 2003. I used an update statement like
    UPDATE dbo.tableA
    SET Datepart (yyyy,TranDt) = Datepart (2003,TranDt)

    This did not work - is there anything I need to change in the update statement to make this query do what I want to -

    Thanks!

  2. #2
    Join Date
    Oct 2003
    Location
    Dallas
    Posts
    76

    hope this helps

    run this for an example
    select DATEADD(yyyy, 1, getdate())

    update x
    set x.timefield = DATEADD(yyyy, 1, x.timefield)
    from table x

  3. #3
    Join Date
    Oct 2003
    Location
    Ohio
    Posts
    20
    mkkmg,
    Thanks a million it worked perfect!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •