Change Date Format(DD/MM/YYYY) in SQL SELECT Statement

前端 未结 5 1081
挽巷
挽巷 2021-02-08 08:28

The Original SQL Statement is:

SELECT SA.[RequestStartDate] as \'Service Start Date\', 
       SA.[RequestEndDate] as \'Service End Date\', 
FROM
(......)SA
WHER         


        
相关标签:
5条回答
  • 2021-02-08 08:48

    Changed to:

    SELECT FORMAT(SA.[RequestStartDate],'dd/MM/yyyy') as 'Service Start Date', SA.[RequestEndDate] as 'Service End Date', FROM (......)SA WHERE......
    

    Have no idea which SQL engine you are using, for other SQL engine, CONVERT can be used in SELECT statement to change the format in the form you needed.

    0 讨论(0)
  • 2021-02-08 08:48

    There's also another way to do this-

    select TO_CHAR(SA.[RequestStartDate] , 'DD/MM/YYYY') as RequestStartDate from ... ;
    
    0 讨论(0)
  • 2021-02-08 08:54

    You will want to use a CONVERT() statement.

    Try the following;

    SELECT CONVERT(VARCHAR(10), SA.[RequestStartDate], 103) as 'Service Start Date', CONVERT(VARCHAR(10), SA.[RequestEndDate], 103) as 'Service End Date', FROM (......) SA WHERE.....
    

    See MSDN Cast and Convert for more information.

    0 讨论(0)
  • 2021-02-08 09:08

    Try:

    SELECT convert(nvarchar(10), SA.[RequestStartDate], 103) as 'Service Start Date', 
           convert(nvarchar(10), SA.[RequestEndDate], 103) as 'Service End Date', 
    FROM
    (......)SA
    WHERE......
    

    Or:

    SELECT format(SA.[RequestStartDate], 'dd/MM/yyyy') as 'Service Start Date', 
           format(SA.[RequestEndDate], 'dd/MM/yyyy') as 'Service End Date', 
    FROM
    (......)SA
    WHERE......
    
    0 讨论(0)
  • 2021-02-08 09:12

    Try like this...

    select CONVERT (varchar(10), getdate(), 103) AS [DD/MM/YYYY]
    

    For more info : http://www.sql-server-helper.com/tips/date-formats.aspx

    0 讨论(0)
提交回复
热议问题