svge
svge

Reputation: 11

How do I format TRUNC?

For example, I want to run a query that returns how long someone has been registered for.

This works. I get the result

Name, address, 4 6

4 being the year and 6 being the month

However I want the out put to say

4y 6m

How can I do this?

Thank you

Upvotes: 1

Views: 46

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270421

You've done the harder part. You just need to add the elements to the string:

(TRUNC(months_between(sysdate, register_date)/12) ||
 'y ' ||
 MOD(TRUNC(months_between(sysdate, register_date)),12) ||
 'm'
)

Upvotes: 2

Related Questions