check date of birthday

User avatar
sal21
PlatinumLounger
Posts: 4512
Joined: 26 Apr 2010, 17:36

check date of birthday

Post by sal21 »

How do I know if the Born = 12/01/2016 customer is a minor, i.e. under 18, based on the current date?

in this case is thrue

User avatar
HansV
Administrator
Posts: 79522
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: check date of birthday

Post by HansV »

Code: Select all

    Dim DateOfBirth As Date
    Dim IsMinor As Boolean
    DateOfBirth = ...
    IsMinor = (DateOfBirth > DateAdd("yyyy", -18, Date))
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4512
Joined: 26 Apr 2010, 17:36

Re: check date of birthday

Post by sal21 »

HansV wrote:
11 Aug 2022, 09:18

Code: Select all

    Dim DateOfBirth As Date
    Dim IsMinor As Boolean
    DateOfBirth = ...
    IsMinor = (DateOfBirth > DateAdd("yyyy", -18, Date))

wath you think about?

In my code repository:

nato=11/12/2015

If AGE(nato) < 18 Then
stop
End If

Public Function AGE(BirthDate) As Long

M = DateDiff("M", BirthDate, Date)
D = DateDiff("D", DateAdd("M", M, BirthDate), Date)
If D < 0 Then
M = M - 1
End If
AGE = M \ 12

DNASCITA = BirthDate

End Function

note:
is a very old code, 2015

User avatar
HansV
Administrator
Posts: 79522
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: check date of birthday

Post by HansV »

That should work too. I don't know what DNASCITA is for, though.
Best wishes,
Hans