VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This will calculate the age(no of years, no of months, no of days) of a person depending on his bir

by Anil Patel (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Fri 6th December 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This will calculate the age(no of years, no of months, no of days) of a person depending on his birthday

Rate This will calculate the age(no of years, no of months, no of days) of a person depending on his bir



Dim vdt1 As Date
Dim vdt2 As Date
vdt1 = Format(dtpstart, "dd/mm/yyyy")
vdt2 = Format(dtpend, "dd/mm/yyyy")
If vdt1 > vdt2 Then
    MsgBox " Starting year Cannot be greater then Ending Year"
Else
    Call CalcAge(vdt1, vdt2)
End If
End Sub
Public Sub CalcAge(vDate1 As Date, vdate2 As Date)
Dim vYears As Integer, vMonths As Integer, vDays As Integer
vMonths = DateDiff("m", vDate1, vdate2)
vDays = DateDiff("d", DateAdd("m", vMonths, vDate1), vdate2)
    If vDays < 0 Then
        vMonths = vMonths - 1
        vDays = DateDiff("d", DateAdd("m", vMonths, vDate1), vdate2)
    End If
    vYears = vMonths \ 12 ' integer division
    vMonths = vMonths Mod 12 ' only want leftover less than one year
    txtdiff.Text = " Filed on                -  " & Format(vDate1, "dd/mm/yyyy") & vbCrLf & vbCrLf & " Disposed of on  -  " & Format(vdate2, "dd/mm/yyyy") & vbCrLf & vbCrLf & " Duration                -  Years     - Months      - Days: " & vbCrLf & vbCrLf & vbTab & vbTab & vYears & vbTab & vMonths & vbTab & vDays
End Sub

Download this snippet    Add to My Saved Code

This will calculate the age(no of years, no of months, no of days) of a person depending on his bir Comments

No comments have been posted about This will calculate the age(no of years, no of months, no of days) of a person depending on his bir. Why not be the first to post a comment about This will calculate the age(no of years, no of months, no of days) of a person depending on his bir.

Post your comment

Subject:
Message:
0/1000 characters