0

How can we convert 15jan2018 which is a text datatype to 15JAN2018.

I am able to convert if it is date datatype.

1
  • 1
    Are you actually converting anything? Seems like you just need UPPER case. Commented Feb 22, 2019 at 18:33

1 Answer 1

1

You can use to_date:

SELECT to_date('15jan2018', 'DDmonYYYY');

  to_date   
------------
 2018-01-15
(1 row)

Then use to_char to convert it to any format you want:

SELECT to_char(to_date('15jan2018', 'DDmonYYYY'), 'DDMONYYYY');

  to_char  
-----------
 15JAN2018
(1 row)

Of course you can simply use upper in your specific case to convert it to upper case, but I guess that's not what you are looking for.

Finally, PostgreSQL's date input function is pretty flexible, so you can try to simply cast it:

SELECT '15jan2018'::date;

    date    
------------
 2018-01-15
(1 row)

This is useful if the format varies slightly.

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.