• 0

# Time Calculations

## Question

I am building a report and want to create a virtual field which shows the result of subtracting one time/date field from another and then sums the times at the bottom. Ie this is for calculation the time taken to enter data for each record.

Can anyone advise me on code for this?

## Recommended Posts

• 0
Hello Corpcatalog!

There is a standard date function "Datediff".

You can create a Calculated field, add this function in format

Datediff (datepart, startdate, enddate)

Startdate and enddate are fields, datepart - is unit dimensions (year, month, day, hour, minute, second).

E.g., my formula is:

Datediff(hour,[@field:startingDate],[@field:endingDate])

To display the sums of the times - add an Aggregate field, select the created Calculated Field and select the "Sum" in the function field.

You can also use Formula in the Aggregate field.  E.g., if datepart is hour, and I want see result in days, the Formula will be like SUM/24.

Some more details about Calculated and Aggregate fields.

##### Share on other sites

• 0

Hi, you may also want to consider this formula with HH:MM format :

CONVERT(VARCHAR,(Datediff(minute,[@field:Start_date],[@field:End_date])/60))
+':'+
CASE WHEN (Datediff(minute,[@field:Start_date],[@field:End_date])%60) < 10 THEN '0'+CONVERT(VARCHAR,(Datediff(minute,[@field:Start_date],[@field:End_date])%60))
ELSE
CONVERT(VARCHAR,(Datediff(minute,[@field:Start_date],[@field:End_date])%60))
END

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.