1

I have a column with date and timestamp stored as character varying, I need to join to another table that has the same dates (also stored as character varying) but in different positions.

IE is there a way to convert:

"2022/08/03 13:29:59" ----------> "03/08/2022 13:29:59" 

Thanks

4
  • 2
    if possible, wouldn't be better to change both columns to timestamp? Commented Aug 10, 2022 at 15:07
  • 1
    see it yourself: SELECT '2022/08/03 13:29:59'::timestamp, '03/08/2022 13:29:59'::timestamp Commented Aug 10, 2022 at 15:09
  • Thanks Jim, this is a much better option!! Commented Aug 10, 2022 at 15:11
  • I just added an answer with a fiddle that might make my case better. cheers Commented Aug 10, 2022 at 15:14

1 Answer 1

2

The best way would be to change the data type of both columns, as timestamps shouldn't be stored as text. If not possible, a simple cast would do:

SELECT 
  '2022/08/03 13:29:59'::timestamp,
  '03/08/2022 13:29:59'::timestamp;

      timestamp      |      timestamp      
---------------------+---------------------
 2022-08-03 13:29:59 | 2022-08-03 13:29:59
(1 row)

Demo: db<>fiddle

Sign up to request clarification or add additional context in comments.

Comments

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.