date time

  • Extract time from datetime column along with AM or PM

    select MyDate from X

    SELECT CONVERT(VARCHAR,mydate,108) from X....this only gets the time part but not AM or PM. I need both.

    Thanks

  • Here's how but I need to know... why do you need to do this type of formatting in SQL?

    SELECT STUFF(RIGHT(CONVERT(VARCHAR(50),GETDATE(),109),14),9,4,'')

    --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)

  • Use

    SELECT CONVERT(VARCHAR,GETDATE(),109) or

    SELECT CONVERT(VARCHAR,GETDATE(),100) or

    SELECT CONVERT(VARCHAR,GETDATE(),9)

  • Use

    SELECT CONVERT(VARCHAR,GETDATE(),109) or

    SELECT CONVERT(VARCHAR,GETDATE(),100) or

    SELECT CONVERT(VARCHAR,GETDATE(),9)

  • Mohan Kumar (8/7/2009)


    Use

    SELECT CONVERT(VARCHAR,GETDATE(),109) or

    SELECT CONVERT(VARCHAR,GETDATE(),100) or

    SELECT CONVERT(VARCHAR,GETDATE(),9)

    None of those produce what was asked for.

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

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