Unbound TextBox showing year and month from DOB (1 Viewer)

JPR

Registered User.
Local time
Today, 06:19
Joined
Jan 23, 2009
Messages
192
Hello,
can you please help me with the following code I have places in a unbound txtbox: =DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")<Format([DOB],"mmdd"))

I have a date of birth control. After I type the DOB, I would like to unbound text box to show the age format as years and month. Thank you
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:19
Joined
Sep 21, 2011
Messages
14,052
Try a Search here using 'age in years and months'
 

Minty

AWF VIP
Local time
Today, 13:19
Joined
Jul 26, 2013
Messages
10,355
You aren't quite creating the string the correct way - try this:
Code:
= DateDiff("yyyy",[DOB],Date())& " " &  Int(Format(Date(),"mm")-Format([DOB],"mm"))
Code:
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:19
Joined
Sep 21, 2011
Messages
14,052
I forgot to add, use username arnelgp, as he has contributed to this task several times.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:19
Joined
May 7, 2009
Messages
19,175
Code:
' arnelgp
Public Function Age_YM(Date1 As Variant, Optional Date2 As Variant = 0) As String
    Dim Year1 As Integer
    Dim Month_1 As Integer
    Dim Day1 As Integer
    Dim temp As Date
    Dim sAge As String
    Dim Age As Variant

    Age = "Unknown"

    If Trim(Date1 & "") = "" Then Exit Function
    If IsDate(Date1) = False Then Exit Function

    If Date2 = 0 Then Date2 = Date
    temp = DateSerial(Year(Date2), Month(Date1), Day(Date1))
    Year1 = Year(Date2) - Year(Date1) + (temp > Date2)
    Month_1 = Month(Date2) - Month(Date1) - (12 * (temp > Date2))
    Day1 = Day(Date2) - Day(Date1)
    If Day1 < 0 Then
        Month_1 = Month_1 - 1
        Day1 = Day(DateSerial(Year(Date2), Month(Date2) + 1, 0)) + Day1 + 1
    End If
    If Year1 > 0 Then
        Age = Year1
        If Year1 > 1 Then
            Age = Age & " years "
        Else
            Age = Age & " year "
        End If
        If Month_1 > 0 And Day1 = 0 Then
            Age = Age & " and "
        End If
    End If
    If Month_1 > 0 Then
        Age = Age & Month_1
        If Month_1 > 1 Then
            Age = Age & " months "
        Else
            Age = Age & " month "
        End If
    End If
    sAge = Trim(Replace(Age, "  ", " "))
    If InStr(sAge, "and") = 1 Then _
        sAge = Trim(Replace(sAge, "and", ""))
    Age_YM = sAge
End Function
 

Users who are viewing this thread

Top Bottom