Format date when performing Update in the registry - Postgresql

Asked

Viewed 527 times

0

I am saving in my database the date that certain record is changed, however the format that it is saved is (YYYY-MM-DD), the SQL command used so far is as follows::

update public.transportadora set status = 'Ativo', user_update = 'Teste', data_alteracao = current_date where codigo = 3

and the record goes like this:

inserir a descrição da imagem aqui

My need is for the date to be in sequence DD-MM-YYYY, that is to say, 27/03/2017

  • 1

    You need to adapt to recognize the database as a transparent layer made to store and manipulate data. It will return a type of data, the display of this type is not necessarily his obligation. You can display as you wish

2 answers

2


At the database level, if you selected this field as a date field or timestamp you do not format the date, who does this is the database itself, what you can do is take this data and format programmatically, for example in java can use the SimpleDateFormat in php if I’m not mistaken has the function date(); It says there which language is using that someone will give a more precise answer.

  • My question is whether in the Update command itself I could format the way the date is saved in the database not itself in the select but from what you’ve already said it’s not possible

  • In the case of FETCH the data you can use DBMS functions to do this for example the Mysql date, but to save eh the DBMS that decides how to save.

  • Yes, I could tell by what you said

0

When displaying use: to_char(seu_campo_data, 'DD-MM-YYYY')

  • I have no difficulty to format to display, the reply from @Victorharturdecarvalho showed this

  • You are confusing storage format with display format. You do not modify the storage format of a date field in Postgresql, but you can change the display format to the way you find convenient.

Browser other questions tagged

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