output time only

  • Hi,

    The output from my Time field in my query is 2015-01-07 10:33:00.000.
    I would like my query to output the Time only. My query is: Select DateOfvisit, Team, DatePart(Hour,TimeOfVisit) As HourSlot, Count(*) As Visits from events

    Thanks

  • Unsure which column you want the time only in your query, but add or replace with cast(TimeOfVisit as TIME)
    This will give you hh:mm:ss.nnnnn

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle

  • Thanks is there anyway to remove the seconds?

  • Yes, use CONVERT(VARCHAR(5),TimeOfVisit,108)

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle

  • Thank you

  • Henrico Bekker - Thursday, June 28, 2018 4:35 AM

    Yes, use CONVERT(VARCHAR(5),TimeOfVisit,108)

    Consider the eventual "Death by a thousand cuts" that every database ends up going through and use CHAR(5) instead of VARCHAR(5).

    --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 6 posts - 1 through 5 (of 5 total)

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