Compare if dates are in the period

0

I need to know the user's date of birth if he was born during the period of the military dictatorship.

The military period in Brazil began on 01/04/1964 and ended on 03/15/1985, and all those born between that period would be treated as true, those before and after the period would be treated as false.

I'm trying this way, but I'm getting it wrong

Function ditadura(data)

d = day(data)
m = month(data)
a = year(data)

if a >= 1964 and m >= 04 and d >= 01 or a <= 1985 and m <= 03 and d <= 15 then 
    ditadura = "Você nasceu em um período de ditadura militar"
end if

end function

How can I resolve this?

    
asked by anonymous 04.04.2018 / 14:42

1 answer

2

You can compare date and date directly:

Function ditadura(data)

   inicio = CDate("01/04/1964")
   fim= CDate("15/03/1985")
   If data >= inicio And data <= fim Then
      ditadura = "Você nasceu em um período de ditadura militar"
   Else
      ditadura = ""
   End If

end function

Just look at the server's date format to set the start and end dates, you may need to use M / D / A format

    
04.04.2018 / 15:05