How can I calculate the hours between two date/tim...
# suiteanalytics
y
How can I calculate the hours between two date/time fields? Thanks in advance.
g
({date1} - {date2})*24
Formula (numeric), and i'd suggest using the rounding function as well
y
Thanks for the quick response I get an error of: An unexpected error has occurred. Please click here to notify support and provide your contact information.
g
Hmmmmm
Without knowing what else you have in your search, I'm stumped as to what could be causing it. If you remove that formula, it works?
y
Yep. it's a really basic search of a custom record which hold 2 fields (type date/time) and I would like to have a formula that will calculate the hours between those dates.
g
What happens if you just subtract one field from the other?
{date1} - {date2}
?
y
Still the same error. Very strange! ☹️
g
That is very bizarre. Is it possible that they are formatted to appear like date/time fields, but are actually text?
Other than that, i'm all out of ideas. Sorry! If you post a screen shot of how you have the search configured, that might help.
y
That it the search. the formula for days are fine
Search of a custom record
these field's type are date/time i.e 20/2/2020 155600
g
Have you tried duplicating the formula for days and multiplying that by 24? I see the NVL in there which means that some don't have an end date, right? That could be the cause of the error.
y
Now it's not showing the error. but it show the day as hours but i would like to see 8 hours instead of 0. the purpose of that is SLA
g
0 hours appears when start date = today? You could probably use CASE or DECODE to check if the formula will = 0, and if it does then output 8, and if it doesn't then output the result of the formula.
y
I'm manged to achieve that with this formula (text): TRUNC(NVL({custrecord_end_date},{today}))-TRUNC({custrecord_start_date}) || ' Days ' || CEIL(ABS(TO_CHAR(NVL({custrecord_end_date},{today}),'hh24')-TO_CHAR({custrecord_start_date},'hh24'))) || ' Hours '