Reputation: 141
I am using Oracle 12c version. I have a column which is integer data type and it represents total minutes. I need to convert it into HOURS:MINUTES format.
Could someone suggest how to do that?
Thanks, Venu
Upvotes: 0
Views: 95
Reputation: 481
You can use the to_date built-in function to translate the integer into a valid time.
Example
SQL> select to_char ( to_date ( '2300', 'HH24MI'), 'HH:MI AM') integer_time from dual;
Upvotes: 0
Reputation: 4539
This is a fairly easy thing to accomplish using a series of built in functions.
to_char(floor(field / 60) || ':' || to_char(mod(field, 60), 'FM00')
Breaking it down:
to_char(floor(field / 60)
field / 60
gets us the number of hoursfloor()
ensures that we don't have to deal with decimalsto_char()
converts it to a string so we can concatenate it.|| ':' ||
mod(field, 60)
gets the remainder of field / 60
to_char()
again converts to a string for the concat step'FM00'
ensures that we keep our leading zeros.Obviously, you'll need to replace field
with whatever the field in your database is called.
Upvotes: 3