Update the time in already populate datetime field

  • Hi,

    I have 2000 rows of data and they all have the date and time in them for field "EntryDate" I need to run a query to update all of the times from "00:00:00" to "06:00:00" normally i would use an update and replace query to update text fields which works great but with time it won't work. There are no errors and it says all the records have been updated but they still have 00:00:00

    any advice on this would be great. Thanks, oh and here is a sample to look at.

    use testdb

    CREATE TABLE T1(

    EntryDate datetime NOT NULL

    )

    INSERT INTO T1 VALUES('2009/08/19 00:00:00');

    SELECT EntryDate from T1

    --Query i tried to do the update!

    --update T1 set entrydate = replace(entrydate, '00:00:00','06:00:00')

  • update T1 set entrydate = '2009/08/19 06:00:00'

    OR

    update T1 set entrydate = DATEADD( hh, 6, entrydate )

    CEWII

  • Thanks for that the second option worked a treat.

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

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