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.
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.
Convert your current date into “number of minutes since X”.
Add your new minutes to the result from 2.
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.
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.
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 so I ended up with a nicer (and slightly cleaner) database solution. But perhaps these variables will help a future Bobber!