0

Need to transfer numeric columns with numbers like '201 711' and '201 806' to dates like '2017-11-01' and '2018-06-01' ('YYYY-MM-01'). When I try this

select to_date(debt_max_period,'YYYY-MM') as date1 from debt;

I get

SQL Error [42883]: ERROR: function to_date(numeric, unknown) does not exist.

Will be thankful for any ideas!

2 Answers 2

1

You need to cast the number to a text/varchar value. As the number doesn't contain the - character, you also need to remove that from your format mask.

to_date(debt_max_period::text, 'yyyymm')
Sign up to request clarification or add additional context in comments.

Comments

0

Oracle -

select TO_CHAR(TO_DATE(START_DATE,'YYYYMMDD'),'YYYY-MM-DD') STARTDATE from account

You can use like below as well. Postgresql -

select TO_CHAR(TO_DATE(START_DATE::text,'YYYYMMDD'),'YYYY-MM-DD') STARTDATE from account

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.