By Hour

  • I have field date :3/31/2009 12:00:00 AM

    I need to have result as:

    Date Time

    3/31/2009 12:00:00 AM

    How can I do it?

    Thank you

  • Not quite what you may have been looking for, but it does separate the date and time.

    declare @TestDate datetime;

    set @TestDate = getdate();

    select

    @TestDate as TestDate, -- Original Source Date

    convert(char(10), @TestDate, 101) as Date, -- Date Portion

    convert(Char(12), @TestDate, 108) as [Time] -- Time Portion

  • Thank you:-)

  • Krasavita (6/26/2009)


    Thank you:-)

    Heh... wait a minute, now.... splitting the date and time is normally a really, really bad thing to do. Why do you need to do this?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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