Convert to Datetime MM/dd/yyyy HH:mm:ss in Sql Server

前端 未结 4 846
南方客
南方客 2021-02-19 00:57

How to convert given date format to MM/dd/yyyy HH:mm:ss

I tried this one below but not achieved. Can anyone help me?

SELECT CONVERT(VARCHAR(         


        
相关标签:
4条回答
  • 2021-02-19 01:39

    use

    select convert(varchar(10),GETDATE(), 103) + 
           ' '+
           right(convert(varchar(32),GETDATE(),108),8) AS Date_Time
    

    It will Produce:

    Date_Time 30/03/2015 11:51:40

    0 讨论(0)
  • 2021-02-19 01:42

    Try below:

    SELECT CONVERT(VARCHAR(20), GETDATE(), 101)
    
    0 讨论(0)
  • 2021-02-19 01:55

    Supported by SQL Server 2005 and later versions

    SELECT CONVERT(VARCHAR(10), GETDATE(), 101) 
           + ' ' + CONVERT(VARCHAR(8), GETDATE(), 108)
    

    * See Microsoft's documentation to understand what the 101 and 108 style codes above mean.

    Supported by SQL Server 2012 and later versions

    SELECT FORMAT(GETDATE() , 'MM/dd/yyyy HH:mm:ss')
    

    Result

    Both of the above methods will return:

    10/16/2013 17:00:20
    
    0 讨论(0)
  • 2021-02-19 01:59
    Declare @month as char(2)
    Declare @date as char(2)
    Declare @year as char(4)
    declare @time as char(8)
    declare @customdate as varchar(20)
    
    set @month = MONTH(GetDate());
    set @date = Day(GetDate());
    set @year = year(GetDate());
    
    set @customdate= @month+'/'+@date+'/'+@year+' '+ CONVERT(varchar(8), GETDATE(),108);
    print(@customdate)
    
    0 讨论(0)
提交回复
热议问题