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

Asked

Viewed 49,607 times

10

I would like to format the fields DataAfr and DataTrm of the kind DATETIME, in the 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 treat SELECT ?

2 answers

17


User the 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 still have the option to use the Format.

DECLARE @d DATETIME = getdate();  
SELECT FORMAT (@d, 'd', 'pt-BR' ) 

7

Browser other questions tagged

You are not signed in. Login or sign up in order to post.