2

Can anyone tell please tell me how to change 2018-01-15T08:54:45.000Z to 2018-01-15 08:54:45 in PostgreSQL.

Here my timestamp: 2018-01-15T08:54:45.000Z is in text format. I need to split it into two different columns like one for the only date:2018-01-15 and another is for only time:08:54:45

1 Answer 1

6

You should be able to directly cast your text to a timestamp and then cast again to date or time to get two different columns:

SELECT
  ('2018-01-15T08:54:45.000Z'::timestamp)::time AS time,
  ('2018-01-15T08:54:45.000Z'::timestamp)::date AS date
; 
Sign up to request clarification or add additional context in comments.

1 Comment

Hello @Andrew Whitaker, many thanks for your answer. This code converting the timestamp properly but it shows some extra digit after second as example 15:30:59.00163. In my case its work like UPDATE table_name SET time = ('timestamp'::TIMESTAMP)::timestamp(0);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.