## Decimal to HH:MM calculation

0
Hi,   I have two Date and Time attributes in my entity (1. Start Time and 2. End time). And one more attribute TimeDiff, its value is calculated as the hoursbetween these two time . hoursBetween(\$TimeSheetTaskActivity/TaskStartTime,\$TimeSheetTaskActivity/TaskEndTime) =  TimeDiff The output is Decimal. I want the difference as HH:MM format. Can someone help me on how to convert the decimal value to HH:MM .   Thanks.
1

Hi Ramya,

You could create a date time variable, for example 2023-01-01 00:00 and add the hours from your decimal variable by using the function addHours(). The next step is to format your datetime variable as a string and use the function parseDateTime(HH:mm) to get the hours and minutes form your datetime variable.

Hope this helps!

2

Hi Ramya,

the result is a decimal of hours between two DateTime attributes.

So for example:

Start (DateTime) 2023-02-28 13:30 and End (DateTime) 2023-02-28 16:00 would result in a decimal (2.5 hours) when using hoursBetween.

If you need a string in the format HH:mm you could do something like this:

1. Save the hours between in a variable:
\$hoursDecimal = hoursBetween(\$Start, \$End)
In the example: \$hoursDecimal = 2.5

2. Save the hours part in a variable:
\$hours = floor(\$hoursDecimal)
In the example: \$hours = 2

3. Calculate and save the minutes in a variable:
\$minutes = round((\$hoursDecimal – \$hours) * 60)
In the example: \$minutes = 30

4. Save the hours and minutes in your desired string format:
\$resultString = toString(\$hours) + ‘:’ + toString(\$minutes)
In the example: \$resultString = 2:30

Hope this helps!

Cheers,

Jan

PS:

I have put all of this in single steps to make it more understandable. You can also combine all of that in one step as well. See below: