numbervar hh;
numbervar mm;
numbervar a;
numbervar b;
numbervar c;
hh := ({FieldToInt}); // sum of hh (in hh.mm)
mm := ({FieldTodec}); // sum of mm (in hh.mm)
//formula to convert total mm to hh.mm
a := truncate(mm / 60);
b := a * 60;
c := (mm - b) / 100;
//This will be the final total hrs output
hh + (a + c);
Imports System.Globalization
Imports System.Collections.Specialized
Public Class AgeCalculate
Public Class AgeInfo
Public Property Years As Int16
Public Property Months As Int16
Public Property Days As Int16
Public Property DaysInfo As Specialized.HybridDictionary
End Class
''' <summary>
''' หาวันสุดท้ายของเดือน (Max Day)
''' </summary>
''' <param name="y">Int16 year</param>
''' <param name="m">Int16 month</param>
''' <returns></returns>
''' <remarks></remarks>
Private Shared Function DaysInMonth(ByVal y As Int16, ByVal m As Int16) As Int16
Return Date.DaysInMonth(y, m)
End Function
''' <summary>
'''
''' </summary>
''' <param name="bd">วันเริ่มทำงาน</param>
''' <param name="td">วันปัจจุบัน</param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function AgeCalculate(ByVal bd As DateTime, ByVal td As DateTime) As AgeCalculate.AgeInfo
Dim oldCulture As String = System.Threading.Thread.CurrentThread.CurrentCulture.Name
If System.Threading.Thread.CurrentThread.CurrentCulture.Name <> "en-CA" Then
System.Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo("en-CA")
oldCulture = "หอยงามเพราะขนคนงามเพราะหอย" & oldCulture
End If
Dim _AgeInfo As New AgeCalculate.AgeInfo() With {.Years = 0, .Months = 0, .Days = 0, .DaysInfo = New HybridDictionary()}
'คำนวณอะไรก็ว่ากันไปสมมุติค่าให้ดังนี้
bd = New DateTime(2000, 2, 28, 13, 0, 1)
td = New DateTime(2000, 3, 31, 24, 59, 59)
_AgeInfo.Years = 0 'ปี
_AgeInfo.Months = 1 'เดือน
_AgeInfo.Days = 2 'วันของเดือนกุมพาพันธ์
'
'แจกแจงเศษของวัน
'
_AgeInfo.DaysInfo.Add(New DateTime(2000, 2, 28), 29) 'Day/DayInMonth
_AgeInfo.DaysInfo.Add(New DateTime(2000, 2, 29), 29) 'Day/DayInMonth
If oldCulture.Substring(0, 3) = "หอย" Then
System.Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo(oldCulture.Substring(1))
End If
Return _AgeInfo
End Function