I store on MySQL / MariaDB database a duration of type Time.
I read it from Databaserow this way: Self.duration = row.Column("duration").DateTimeValue
I show the value on my list control this way:
Var items() As Entities.TimesheetEntity = Entities.TimesheetEntity.Read
Var list As WebListBox = TimeSheetListBox
Var acc As ?? //pseudo code
list.RemoveAllRows
For each item As Entities.TimesheetEntity in items
list.AddRow (item.duration.ToString(DateTime.FormatStyles.None, DateTime.FormatStyles.Short)
acc = acc + duration //pseudo code
)
Next
mylabel.text = "total duration: " acc.toString //pseudo code
My problem is how can I make an accumulator and display the total duration after my loop?
I donāt know if this is exactly what youāre looking for, but if I want to measure the time duration of a particular operation, I do the following:
// get duration in milliseconds
// set the start value before the code to be measured
Var start As Double = System.Microseconds / 1000
// <== code to time goes here ==>
// now calculate the duration and display it
Var duration As Double = ((System.Microseconds / 1000) - start) / 1000
System.DebugLog(CurrentMethodName + " Code execution took: " + duration.ToString(Locale.Raw, "#0.000š“"))
Note: the above code was copied from elsewhere on the forum, and sorry I donāt remember from who for the credit.
Assuming that the entries are in order by time, you would just use the first entry and last entry to see how much time has passed between the two. No need to add them up in a loop.
dim totalDuration as DateInterval = lastDateTime - firstDateTime
If they arenāt in order, then you can figure that part out in your loop.
dim firstDateTime as DateTime
dim lastDateTime as DateTime
for each item as Entities.TimesheetEntity in items
if firstDateTime = nil or item.duration < firstDateTime then
firstDateTime = item.duration
end
if lastDateTime = nil or item.duration > lastDateTime then
lastDateTime = item.duration
end
next