Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

convert string "hh:mm" to minutes

WestDraytonMay 27 2011 — edited May 30 2011
I need best query that converts input string with time format "hh:mm" into integer that represent offset/length from time '00:00' to "hh:mm" in minutes.
For example '12:59' is 779 minutes starting from '00:00'.
The time format is fixed always, Php ensures it has colon in the middle and 2 digits surrounding it.
My example query:
WITH Timetable AS
 (SELECT '12:59' AS Timevalue FROM Dual)
SELECT Hourpart * 60 + Minutespart AS Minuteoffsetfrom00
FROM (SELECT To_Number(Regexp_Substr(Timevalue, '[^:]+', 1, 1)) AS Hourpart,
             To_Number(Regexp_Substr(Timevalue, '[^:]+', 1, 2)) AS Minutespart
      FROM Timetable);--779 minutes from 00:00
Can you provide better query?

Oracle 10g, Solaris OS.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 27 2011
Added on May 27 2011
11 comments
1,968 views