Link to home
Start Free TrialLog in
Avatar of Cartillo
CartilloFlag for Malaysia

asked on

Add total automatically

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

Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Is this a Sql database?
What is the data type for Time_Duration?
Avatar of Cartillo

ASKER

Hi,

Yes, indeed. I'm using "time(7)" as data type at Time_Duration column.
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.
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

ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

Thanks for the help