BusinessObjects Board

need formula to add minutes to date

:shock:

Does anyone have the formula to add minutes to a date? I searched and there’s an ugly solution floating around,but it’s not floating around here. I have a date (with date and time) and a number (minutes) that I need to add together.

If I try to logic my way through this any further, my head is going to explode. :blue:

Any help rocks! :slight_smile:


JennFisher :us: (BOB member since 2002-06-25)

Can you try to achieve this at the DB level? Which DB?


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

Jen,

If it’s just minutes you need, you can divide this number by 1440 (number of minutes in a day), and add this decimal value to your date. This will add the appropriate minutes.

For Example, in Oracle, I can run:
select to_char(to_date(‘15-JAN-03’)+ .010416667, ‘MON/DD/YYYY hh:mi:ss’) from dual;

This gives me: JAN/15/0003 12:15:00

Fifteen minutes after midnight, which is what I’d expect.

-RM


digpen :us: (BOB member since 2002-08-15)

:crazy_face: You know, if I would have thought for a 1/1440th of a day… I shoulda know that! Thanks lots, digpen! :slight_smile:


JennFisher :us: (BOB member since 2002-06-25)

Does this work in BO? For the life of me I can’t figure it out… I think I’m going :crazy_face:


JennFisher :us: (BOB member since 2002-06-25)

Which DBMS are you using?
What is the code you are trying?
What is the error message?


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

Oracle. And I’ve solved it at the database level… but I’m curious if I can solve it in BO.

I have and . is a date format, a string. shows the date and time of an appointment, the length of the appointment in minutes.

I’m converting this way and that way, dividing by 1440, and just can’t seem to get it to work.

Any Reporter ides?

I might could change to a number in the DB, but I’m already doing that in the report and it doesn’t seem to help… :expressionless:


JennFisher :us: (BOB member since 2002-06-25)

Look at this thread: Variance calculation

Especially Dave’s sample code should be a good starting point:

=((( (ToNumber(SubStr(FormatDate(<DATE2> ,"HH:MM:SS") ,1 ,2))*60*60) + 
(ToNumber(SubStr(FormatDate(<DATE2> ,"HH:MM:SS"), 4, 2))* 60) + 
ToNumber(SubStr(FormatDate(<DATE2> ,"HH:MM:SS"), 7, 2))) - ( 
(ToNumber(SubStr(FormatDate(<DATE1> ,"HH:MM:SS") ,1 ,2))*60*60) + 
(ToNumber(SubStr(FormatDate(<DATE1> ,"HH:MM:SS"), 4, 2))* 60) + 
ToNumber(SubStr(FormatDate(<DATE1> ,"HH:MM:SS"), 7, 2)))) / 3600) + 
(DaysBetween(<DATE1> ,<DATE2>)*24)

I believe there is also a DLL one of the BOB members wrote which allows adding time.


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

Here’s how I would approach this…

  1. Pick a date, any date. 8) Call it X.
  2. Convert your current date into “number of minutes since X”.
  3. Add your new minutes to the result from 2.
  4. Convert that back from a total minutes into days, hours, and minutes to get the date time.

For more precision, use number of seconds instead of number of minutes.

The “relative date” thing is not unusual, it’s what BusinessObjects uses in their repository. It’s also how the BOB forum software dates are stored and manipulated. :wink:

Dave


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

:shock: Brain freeze. How?


JennFisher :us: (BOB member since 2002-06-25)

Number of Days * 1440 +
Number of Hours * 60 +
Number of Minutes

“Number of Days” = DaysBetween(X, YourDateHere)

Since DaysBetween() ignores the time, you get a number of days since the baseline date. Then you use the nasty string functions to extract the hours and minutes, and convert accordingly.

Dave


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

Many, many thanks, all of y’all, who helped me out on this one. I thought I’d check back in with exactly what I did.

My original variables were and .

I created a slew of variables:
[list] = DaysBetween(‘10/18/2002’,)
=ToNumber(FormatDate( ,“H”))
=ToNumber(Left(FormatDate( ,“mm:ss”) ,2))
=(*1440)+(*60)+
=+
=FormatDate(RelativeDate(‘10/18/2002’ ,(/1440)) ,“mm/dd/yyyy”)
=Floor(Mod(< Total Minutes for End> ,1440)/60)
=Mod(Mod( ,1440) ,60)
=ToDate( & " " & FormatNumber( ,“0”) & “:” &FormatNumber( ,“00”) ,“mm/dd/yyyy HH:mm:ss”)[/list]Whew. is the “final” variable I used.

Ironically enough, this still didn’t solve my original problem :roll_eyes: so I ended up with a nicer (and slightly cleaner) database solution. But perhaps these variables will help a future Bobber! :mrgreen:


JennFisher :us: (BOB member since 2002-06-25)