Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format bigint field into a date in Postgresql?

I have a table with a field of type bigint. This field store a timestamp. I want to date format the field like this :

to_char( bigint_field,'DD/MM/YYYY HH24:MI:SS')

I get the following error :

 ERROR: multiple decimal points État SQL :42601 
like image 746
Stephan Avatar asked Mar 30 '11 11:03

Stephan


People also ask

How do I format date in PostgreSQL?

Instead, you should use to_char to format the date when you query it, or format it in the client application. Like: SELECT to_char("date", 'DD/MM/YYYY') FROM mytable; e.g.

How do I convert text to date in PostgreSQL?

The TO_DATE function in PostgreSQL is used to converting strings into dates. Its syntax is TO_DATE(text, text) and the return type is date. The TO_TIMESTAMP function converts string data into timestamps with timezone. Its syntax is to_timestamp(text, text) .

What is the data type for date in PostgreSQL?

The date format for the date data type in PostgreSQL is yyyy-mm-dd . This is the format used for both storing data and for inserting data.

How do I change the date format from YYYY-MM-DD in PostgreSQL?

1) Get the current date To get the current date and time, you use the built-in NOW() function. However, to get the date part only (without the time part), you use the double colons (::) to cast a DATETIME value to a DATE value. The result is in the format: yyyy-mm-dd .


1 Answers

TO_CHAR(TO_TIMESTAMP(bigint_field / 1000), 'DD/MM/YYYY HH24:MI:SS') 
like image 62
Quassnoi Avatar answered Sep 19 '22 10:09

Quassnoi