Add total automatically

Cartillo
Cartillo used Ask the Experts™
on
Hi Experts,

I need Experts help. How to add automatically total sum of data (time) from column TimeIN and TimeOUT at column Total_Duration. At present the data was not automatically count at Total_Duration column. Hope Experts will help create this feature.
Imports MyCompany.Data
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Linq
Imports System.Text.RegularExpressions
Imports System.Web

Namespace Rules
    
    Partial Public Class DataBusinessRules
        Inherits MyCompany.Rules.SharedBusinessRules
        
        <RowBuilder("Data", RowKind.New)>  _
        Public Sub BuildNewData()
            UpdateFieldValue("Total_Duration", "(datediff(HOUR,[TimeIN],[TimeOUT]))")
        End Sub
    End Class
End Namespace

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2015

Commented:
Is this a Sql database?
What is the data type for Time_Duration?

Author

Commented:
Hi,

Yes, indeed. I'm using "time(7)" as data type at Time_Duration column.
Top Expert 2015

Commented:
Confused.

Are you trying to figure out what the new time would be if the interval between TimeIN and TimeOUT were added to it? Part of the confusion comes from the difference in accuracy between the value returned from DateDiff (hours as integer) and the use of time (7) data type for Time_Duration which is something like a millionth of a second accuracy.

If you just want to use Time_Duration as a running total of hours, why not make it an Integer and just add the result of DateDiff to it.
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Author

Commented:
Hi tommyBoy,

I've modify the total duration type as "int" but the return value not showing total duration of it. Attached the script that being used. Hope I have followed the right steps.
Imports MyCompany.Data
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Linq
Imports System.Text.RegularExpressions
Imports System.Web

Namespace Rules
    
    Partial Public Class timeBusinessRules
        Inherits MyCompany.Rules.SharedBusinessRules
        
        <ControllerAction("time", "Calculate", "Total_Duration")>  _
        Public Sub Calculatetime(ByVal time_ID As Nullable(Of Integer), ByVal [date] As Nullable(Of DateTime), ByVal timeIN As Nullable(Of System.TimeSpan), ByVal timeOUT As Nullable(Of System.TimeSpan), ByVal total_Duration As Nullable(Of Integer))
            UpdateFieldValue("Total_Duration", "(datediff(HOUR,[TimeIN],[TimeOUT]))")

        End Sub
    End Class
End Namespace

Open in new window

Top Expert 2015
Commented:
Maybe this:

DatedDiff(DateInterval.Hour, timeIn, timeOUT)

Author

Commented:
Hi,

Thanks for the help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial