When doing the function of the machine, in order to calculate two time difference, need to use a DateDiff function, below to understand this function.
Official explanation:
DateDiff is a time interval that returns between two dates.
Syntax: DateDiff (interval, date1, date2 [, firstdayofweek[, FirstWeekOfYear]])
| Parameters |
Describe |
| Interval |
Must be selected. A string expression that is used to calculate the time interval between date1 and date2 . See the Settings section for values. |
| Date1, Date2 |
Must be selected. The date expression. The two dates used for the calculation. |
| FirstDayOfWeek |
Optional. Constant that specifies the first day of the week. If not specified, the default is Sunday. See the Settings section for values. |
| FirstWeekOfYear |
Optional. A constant that specifies the first week of the year. If not specified, the default is the week in which January 1 is located. See the Settings section for values. |
interval can have the following values:
| Set up |
Describe |
| yyyy |
Years |
| Q |
Quarter |
| M |
Month |
| Y |
Number of days in a year |
| D |
Day |
| W |
Number of days in a week |
| Ww |
Week |
| H |
Hours |
| N |
Minutes |
| S |
Seconds |
The following machine calculates how long it takes between the upper and lower machines as an example
' Calculates the time difference Dim time As Long Dim time1 As Long Dim time2 As Long Dim OT As String = MyList. First.ontime Dim OD as String = MyList. First.ondate time = DateDiff ("n", OD, Today.date) +datediff ("n", OT, TimeOfDay) ' Get a total of how many minutes Dim Ihour as Integer ' Converts a long type of time to an integer type ihour = (int (time/60)) ' Long value is beyond the range of Int and then it will be problematic. Is that the transformed value becomes txtcontime.text = Ihour ' Get hours
This will give you the time to spend on the machine. At the same time, according to the function calculation can also calculate the consumption amount of the machine
Additional: The DateAdd function is similar to its usage, and can be calculated by adding/minus a time interval. Interested in understanding the DATEADD function
This time function is not very difficult, but after the use of the multiplier. Accumulation.
Accumulate--datediff functions