منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
لحساب العمر الكامل بدلالة التاريخ - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : الأقسام التعليمية - المنتدى القديم (http://vb4arb.com/vb/forumdisplay.php?fid=90)
+--- قسم : مكتبة أكواد المنتدى (http://vb4arb.com/vb/forumdisplay.php?fid=111)
+---- قسم : مكتبة أكواد .net (http://vb4arb.com/vb/forumdisplay.php?fid=117)
+---- الموضوع : لحساب العمر الكامل بدلالة التاريخ (/showthread.php?tid=6179)



لحساب العمر الكامل بدلالة التاريخ - RaggiTech - 17-10-12

كاتب الموضوع : AhmedEssawy


كود :
Public Function GetAge(ByVal Birthdate As System.DateTime, _
Optional ByVal AsOf As System.DateTime = #1/1/1700#) _
As String
'Don't set second parameter if you want Age as of today
'Demo 1: get age of person born 2/11/1954
'Dim objDate As New System.DateTime(1954, 2, 11)
'Debug.WriteLine(GetAge(objDate))
'Demo 1: get same person's age 10 years from now
'Dim objDate As New System.DateTime(1954, 2, 11)
'Dim objdate2 As System.DateTime
'objdate2 = Now.AddYears(10)
'Debug.WriteLine(GetAge(objDate, objdate2))
Dim iMonths As Integer
Dim iYears As Integer
Dim dYears As Decimal
Dim lDayOfBirth As Long
Dim lAsOf As Long
Dim iBirthMonth As Integer
Dim iAsOFMonth As Integer
If AsOf = "#1/1/1700#" Then
AsOf = DateTime.Now
End If
lDayOfBirth = DatePart(DateInterval.Day, Birthdate)
lAsOf = DatePart(DateInterval.Day, AsOf)
iBirthMonth = DatePart(DateInterval.Month, Birthdate)
iAsOFMonth = DatePart(DateInterval.Month, AsOf)
iMonths = DateDiff(DateInterval.Month, Birthdate, AsOf)
dYears = iMonths / 12
iYears = Math.Floor(dYears)
If iBirthMonth = iAsOFMonth Then
If lAsOf < lDayOfBirth Then
iYears = iYears - 1
End If
End If
Return iYears
End Function