SQL Server 2014 datetime format

  • This is a part of a procedure that I have trouble with :

    declare
     @UpdateDate VARCHAR(21) ,

    -- date and user
    SELECT
    @UserName = SYSTEM_USER ,
    @UpdateDate = CONVERT(VARCHAR(8), GETDATE(), 112)
    + ' ' + CONVERT(VARCHAR(12), GETDATE(), 114)

    First one it seems gives me :  jan 15 2017  2:32PM
    Second: 20170115 14:32:46:627

    I would like both the dates to be like  : 15.01.2017 14:00

    I have tried all afternoon to get it right from various examples but cant make it
    right.

  • Senchi - Sunday, January 15, 2017 6:42 AM

    This is a part of a procedure that I have trouble with :

    declare
     @UpdateDate VARCHAR(21) ,

    -- date and user
    SELECT
    @UserName = SYSTEM_USER ,
    @UpdateDate = CONVERT(VARCHAR(8), GETDATE(), 112)
    + ' ' + CONVERT(VARCHAR(12), GETDATE(), 114)

    First one it seems gives me :  jan 15 2017  2:32PM
    Second: 20170115 14:32:46:627

    I would like both the dates to be like  : 15.01.2017 14:00

    I have tried all afternoon to get it right from various examples but cant make it
    right.

    DECLARE @UpdateDate VARCHAR(20)
    SELECT
    @UpdateDate = CONVERT(VARCHAR(10), GETDATE(), 104) + ' ' + CONVERT(VARCHAR(5), GETDATE(), 114)
    PRINT @UpdateDate

    Output
    /*
    15.01.2017 16:11
    */

    Igor Micev,My blog: www.igormicev.com

Viewing 2 posts - 1 through 1 (of 1 total)

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