TIMESTAMP for EN MYSQL date/time

Asked

Viewed 45 times

1

How do I return the Brazilian date in the database column so that it looks like this 29-04-2020 17:02:02, because he’s returning like this 2020-04-29 17:02:02.

create database teste;
use teste;

CREATE TABLE cliente (
  cd_cliente INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  nome VARCHAR(30),
  cpf VARCHAR(14),
  telefone VARCHAR(15),
  email VARCHAR(50),
  cidade VARCHAR(30),
  bairro VARCHAR(30),
  rua VARCHAR(30),
  numero INT,
  data_cadastro TIMESTAMP(0)
);

insert into cliente (nome,cpf,telefone,email,cidade,bairro,rua,numero,data_cadastro)
values
('João','111.111.111-01','(77) 12345-1234','[email protected]','Guanambi','Santo Carlos','Alguma',123,CURRENT_TIMESTAMP);
select * from cliente;
  • Use the function DATE_FORMAT to obtain the date in the desired format for display.

  • @anonymity where I put it DATE_FORMAT? Can you describe in code?

1 answer

1

I suggest you include in the default mode the date and only at the time of the query turn to the desired format. Type:

SELECT DATE_FORMAT('2020-04-29', '%d de %M de %Y');

You can set the database to en too, which I do not recommend because it may affect other users/applications.

SET GLOBAL lc_time_names=pt_BR;

Browser other questions tagged

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