date format

  • how do I display a date as "Tuesday, July 31, 2007" and where do I find this on BOL? I can't seem to find anything under format or date.

    Thanks again!

  • and display just the time part of a datetime: "4:15pm" ?

  • Heh... the reason why you didn't find it in Books Online is because formatting dates for a GUI in SQL is a really bad idea for about a thousand reasons, not the least of which is what format will be shown in another country if you sell your GUI overseas?

    That, not-with-standing, all the parts (operative word is "parts" ) of what you want are actually in Books Online... you just need to find them all and put them together... like this...

     SELECT DATENAME(dw,GETDATE()) + ', '

          + DATENAME(mm,GETDATE()) + ' '

          + DATENAME(dd,GETDATE()) + ', '

          + DATENAME(yy,GETDATE()) AS LongDate,

            RIGHT(CONVERT(VARCHAR(26),GETDATE(),100),7) AS TimeOnly

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

  • Thanks, Jeff. You know you're talking to a rookie. Or at least not a real SQL person. I will format on the frontend as you suggest.

  • It's ok... that's why all the smiley faces...    you're doing the right thing... when you have a front end involved, let it do the date formatting according to local settings.

    And, thank you for the feedback.

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

  • dates are always ticky, watch out for them especially when using different formats for the front end and the backend.


    Everything you can imagine is real.

  • That's why you shouldn't format in the backend...

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

  • Read the post, Joe... he's a rookie and he said he'd take the advice I gave him to format in the front end

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

  • Heh... and you're good at it, too   Good "seeing" you again.

    --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 9 posts - 1 through 8 (of 8 total)

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