# Hours Between two Date/Times

Does anyone know how to calculate the number of hours or fractional days between two date/time values?

So, if I have 1/1/2009 6:00 AM and 1/1/2009 12:00 PM, how do I get to either 6 hours or .25 days?

THANKS!

jdean1012 (BOB member since 2007-06-26)

Hi,

This topic will give you an idea how it can be accomplished:

Marek Chladny (BOB member since 2003-11-27)

Thanks man! Unfortunately, I do not think this will work for me because often, the start and end date are the same date. So, the Days between function is always 0 or 1 depending on the hours, so the seconds will always be 86400 or 0. Am I wrong about that? I am pretty new to this date/time calculation stuff.

Thanks again!!!

jdean1012 (BOB member since 2007-06-26)

You could try converting the datetime to a string, then substringing out the various time elements, converting each bit to a numeric and adding them together. Then when you have a number representing the time for each date, subtract them and convert the result back to a date.

Fiddly and probably slow to process. Youâ€™d be better off doing it at universe level where youâ€™ve got better functions to manipulate the dates.

Debbie

Debbie (BOB member since 2005-03-01)

BO simply doesnâ€™t do time math. As suggested, youâ€™ll have to do some ugly string manipulation. This really has to be done in the universe.

Steve Krandel (BOB member since 2002-06-25)

The link I posted above provides a way how to do the string manipulations to get the result. As you can see, itâ€™s not very nice. But itâ€™s feasible.

However, as both above posters mentioned, this sort of calculation is better to be done on the database level because a database gives you more functions for the dates manipulations and calculations than what BO can offer.

Marek Chladny (BOB member since 2003-11-27)