How to calculate Age in Years and Months in vb.net

Home Forums General Programming Visual Basic .Net How to calculate Age in Years and Months in vb.net

This topic contains 0 replies, has 1 voice, and was last updated by  Hirendra Sisodiya 6 years, 5 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #3730

    hello friends
    if you are looking the code for calculating time interval such as Age, then you can use the following function.

    [code title=”use DateDiff function”] Private Function CalculateAgeString(ByVal StartDate As DateTime, _
    ByVal EndDate As DateTime) As String
    Dim dt As Long = DateDiff(DateInterval.Month, StartDate, EndDate)
    Dim years As Integer = dt \ 12
    Dim months As Integer = dt Mod 12
    Dim strAge As String = “”
    If months = 0 Then
    strAge = years & ” years”
    Else
    strAge = years & ” years” & ” ” & months & ” month”
    End If
    Return strAge
    End Function
    [/code]
    Try this and let me know

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.