Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting of dates subtraction 1

Status
Not open for further replies.

ddrillich

Technical User
Jun 11, 2003
546
US
Good Day,

We are trying to format the max - min value (is it a date?) into minutes and seconds. How can we do it? The following fails...

Code:
select to_char(to_date(max - min), 'DD:MM') from (select min(timestamp) min, max(timestamp) max from wfeventssummary where workflowid = '12232' and transitionname ^= 'null')

Regards,
Dan
 
Here's a blunt object approach that should work. I'm sure others will have something more elegant:

Code:
SELECT floor(numseconds/60)||':'||to_char((numseconds - floor(numseconds/60) * 60),'09')
  FROM (SELECT (max(timestamp) - min(timestamp)) * 86400 AS numSeconds 
          FROM wfeventssummary 
         WHERE workflowid = '12232' AND transitionname ^= 'null')
 
Thank you carp.

We did get an error for this query -

Code:
ORA-00932: inconsistent datatypes: expected NUMBER got INTERVAL DAY TO SECOND

Regards,
Dan
 
The following does work -

Code:
select x * 84600 from (
 SELECT ( max(cast (timestamp as DATE)) - min(cast (timestamp as DATE)  )  )  as x from wfeventssummary WHERE workflowid = '12232' AND transitionname ^= 'null'
 )

Regards,
Dan
 
A bit better -

Code:
 SELECT floor(numseconds/60) || ':' || to_char( (numseconds - floor(numseconds/60)*60),'09') from (
 select x * 84600 as numseconds from (
 SELECT ( max(cast (timestamp as DATE)) - min(cast (timestamp as DATE)  )  )  as x from wfeventssummary WHERE workflowid = '12232' AND transitionname ^= 'null'
 )
 )

Regards,
Dan
 
Sorry - you are using timestamps and I am using dates. I missed that. Try this:
Code:
SELECT (extract(day from delta)*1440 + extract(hour from delta)*60 + extract(minute from delta))||':'||to_char(round(extract(second from delta)),'09') 
  FROM (SELECT (max(timestamp) - min(timestamp)) AS delta 
          FROM wfeventssummary 
         WHERE workflowid = '12232' 
           AND transitionname ^= 'null')
You may want to use FLOOR or CEIL instead of ROUND to handle the seconds fraction.
 
Glad to hear it. The first one will work on DATE datatypes (in case you ever want to do the same thing with a different type).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top