In PostgreSQL, I need to update the date in the date column. The value in the database is stored in the date format. But from the client the date comes in unix format. How can I convert a unix date value to date format?

  • one
    to_timestamp , you need the function to_timestamp , then you need to understand how the request comes from the client and where you can do the conversion with this function. The question is not enough details for this. - Fine
  • What format do you mean? - Roman C
  • @ Small client application on reactjs. There, the operator selects the date in the calendar and the received date is sent to the server (php) in unix format, for example, the date 1522789200 (for the user it is April 4, 2018, but with the time zone offset of +3). Conversion would be desirable to do directly in the sql query on the server. - cheerful_weasel
  • @RomanC in postgresql is DATE format - cheerful_weasel
  • @cheerful What driver do you connect to the database? - Roman C

1 answer 1

I found the answer myself.

to_timestamp (: planterminUnix) :: date

where: planterminUnix is ​​a number representing a date in unix epoch format.

  1. At first we convert in timestamp
  2. Then cast to date