How to updte time in datetime, please help me

  • Hello every one,

    I have data type datetime:

    theDate

    2012-03-27 11:12:33.073

    2012-03-27 12:11:33.075

    2012-03-27 13:10:33.076

    I want update field theDate to:

    theDate

    2012-03-27 00:00:00.000

    2012-03-27 00:00:00.000

    2012-03-27 00:00:00.000

    Help me, please.

    Thank you very much.

  • Instead of just telling you, how about I point you at one reference that may help you with some of what you are trying to accomplish:

    http://www.sqlservercentral.com/blogs/lynnpettis/2009/03/25/some-common-date-routines/

  • Thank you very much, I have done it. 🙂

  • Okay, glad to hear it. Now, you on the other hand, should post the code you wrote to solve your problem. It may help someone else who may have a similar problem, plus it is proper forum etiquette.

  • Personally, I find a cast more clean code, I have not done any performance testing though to see if it is performing any differently than dateadd/datediff:

    declare

    @dt datetime;

    select @dt = cast(getdate() as date)

    select @dt



    Ole Kristian VelstadbrĂĄten BangĂĄs - Virinco - Facebook - Twitter

    Concatenating Row Values in Transact-SQL[/url]

  • Hi every one, this is my solution.

    update table_name

    set theDate = dateadd(dd, datediff(dd, 0, theDate), 0)

Viewing 6 posts - 1 through 5 (of 5 total)

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