BusinessObjects Board

Days Between

Yes…I searched! :mrgreen:

I want to put the “days between” in my universe rather than in my report. I am using DB2. I can use the “days” command and calculate that as a number. That’s good…but not good enough!

I need to calculate the days between two date/timestamps. My result should account for the hours, minutes, and seconds between the operations. Any suggestions on how to get this to the accuracy level I need?

Thanks!


Eileen King :us: (BOB member since 2002-07-10)


Dave Rathbun :us: (BOB member since 2002-06-06)

You remain my hero! :mrgreen: Thanks!


Eileen King :us: (BOB member since 2002-07-10)

However…

This is strange…I create an object called elapsed hours. The select statement is

HOUR(ORDERDIM_V2.EFFTIME-ORDERDIM_V2.LODTE)

It returns a result of 17. That’s right!

Since I really want to calculate days I want 17/24 to get the partial day. When I create another object

(HOUR(ORDERDIM_V2.EFFTIME-ORDERDIM_V2.LODTE))/24

It returns a result of 0.00. That’s wrong!

If I do the math in the report of “elapsed hours/24” it gives me .71 which is what I’m looking for.

This is v61a…any thoughts? :confused:


Eileen King :us: (BOB member since 2002-07-10)

What happens when you try:

(HOUR(ORDERDIM_V2.EFFTIME-ORDERDIM_V2.LODTE))/24.0

Andreas :de: (BOB member since 2002-06-20)

You’re my hero too!!! :mrgreen:

Can anyone explain why I needed to add the decimal place???


Eileen King :us: (BOB member since 2002-07-10)

Sounds like an implicit Data Type conversion. Without the decimal point the DBMS considers the result set to be INTEGER (-1, 0, 1 , 2, 3,…), with the decimal point it converts it behind the scenes to data type REAL (-1.23, 0.0, 5.74, …).


Andreas :de: (BOB member since 2002-06-20)

That is the screwiest thing I think I’ve seen yet!!! Thanks for the help…

So for those following the suspense, the calculation I’ve arrived at to calculate the elapsed difference in to 100ths of a days (with timestamps) is

(days(ORDERDIM_V2.EFFTIME)-days(ORDERDIM_V2.LODTE))+((HOUR(ORDERDIM_V2.EFFTIME-ORDERDIM_V2.LODTE))*60+MINUTE(ORDERDIM_V2.EFFTIME-ORDERDIM_V2.LODTE))/1440.0

:cheers:


Eileen King :us: (BOB member since 2002-07-10)

Alright - I was avoiding this but could no longer contain myself. :lol:
I don’t understand all the contortions you are going thru. My little DB2 SQL reference say that timestamp durations (subtracting) return DEC(20,6) format – that format is ccyymmddhhmmss.micros. I would do the subtraction and then parse out whatever part of that you need.

Date durations return DEC(8,0) as yyyymmdd so subtracting a birthdate from current date might give you 000410530 or 41 years, 5 months, 30 days.
But then I may be wrong cause I always have to look this stuff up and figure it all out again. :rotf:


scott copeland (BOB member since 2002-08-15)

What I was trying to do was to get the elapsed time in days…the system I’m working on in Delivery Performance so they want to see all kinds of date/timestamps subtracted from one another to get the duration of an activity. I needed to get it in days…to the 1/100th of the day.

If there’s a better way, let me know…this was what my warped little mind came up with…

I needed to figure out how to turn five months, two days, seventeen hours, and thirty minutes into 154.76 days… :mrgreen:

All positive criticism appreciated! :rotf:


Eileen King :us: (BOB member since 2002-07-10)

Eileen,

You should download SQL cookbooks by Graeme Birchall and have a look at what he has to say on the DB2 ‘TIMESTAMPDIFF’ function.

There is an accuracy issue it seems, but it may be good enough after all :lol:


blom0344 :netherlands: (BOB member since 2002-09-04)

Talking about Days Between:

If my variables are set like so:

DaysBetween(12/07/12; 12/01/12)

Then shouldn’t I get a negative -6?! I am getting 6

I don’t recall that the function returns the absolute value.


Joealyche (BOB member since 2012-02-29)

Never mind, the developer had an Alerter set which impacted the result.

Thanks anway. :slight_smile:


Joealyche (BOB member since 2012-02-29)