How to format a DateTime field in the Brazilian format dd / MM / yyyy?

6

I would like to format the DataAfr and DataTrm fields of type DATETIME , in Brazilian date format dd / MM / YYYY instead of the American format yyyy-mm-dd hh: mm: ss

SELECT 
     e.NmrCnt AS [Contrato]
    ,e.NmrSerie AS [Serie]
    ,e.DataAfr AS [Data Aferição]
    ,e.DataTrm AS [Data Término]
FROM
tbl_Eqp e

How should I deal with SELECT ?

    
asked by anonymous 21.09.2016 / 14:55

2 answers

6

User or Convert , with the parameters below.

select getdate() as datanormal, Convert(varchar(10),getdate(),103) as dataformatada

In your case.

SELECT 
     e.NmrCnt AS [Contrato]
    ,e.NmrSerie AS [Serie]
    ,Convert(varchar(10), e.DataAfr,103) AS [Data Aferição]
    ,Convert(varchar(10), e.DataTrm,103) AS [Data Término]
FROM
tbl_Eqp e

You would still have the option to use Format .

DECLARE @d DATETIME = getdate();  
SELECT FORMAT (@d, 'd', 'pt-BR' ) 
    
21.09.2016 / 15:01
6
CONVERT(VARCHAR, DataAfr, 103) AS [Data Aferição]

Documentation .

If you are using at least SQL Server 2012, you can use the FORMAT() function with the Brazilian option.

    
21.09.2016 / 15:01