Date Format (mm/dd/yyyy hh:mm), no seconds or milliseconds

  • select FORMAT(Convert(datetime,GETDATE (),103),'MM/dd/yyyy HH:mm')

  • Rohit Machhi wrote:

    select FORMAT(Convert(datetime,GETDATE (),103),'MM/dd/yyyy HH:mm')

     

    While that's incredibly simple, as it was designed to be, FORMAT has been tested and documented as being 44 times slower than even poor renditions.  Until MS fixes the performance issues with FORMAT (and they won't), don't use FORMAT.

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

  • Because BOL doesn't list/describe all of the available CONVERT styles...

    DECLARE @n INT = 0, @v nvarchar(100);
    WHILE @n < 10000
    BEGIN
    BEGIN TRY
    SELECT @v = CONCAT(@n, N' ', CONVERT(NVARCHAR(50), GETDATE(), @n));
    RAISERROR(@v, 0, 1);
    SET @n += 1;
    END TRY
    BEGIN CATCH
    SET @n += 1;
    END CATCH;
    END;

     

Viewing 3 posts - 16 through 17 (of 17 total)

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