Hello,
I'm trying to replicate a VB Function for age. I can't seem to get the syntax right... can someone please assist me?
WHAT I HAVE (INVALID SYNTAX):
CASE WHEN IFNULL("Employee Personal Attributes"."Employee Birth Date") THEN 0 WHEN (MONTH("Employee Personal Attributes"."Employee Birth Date")) < CURRENT_DATE) Or MONTH(CURRENT_DATE) AND DAY("Employee Personal Attributes"."Employee Birth Date") <= DAY(CURRENT_DATE) THEN TIMESTAMPDIFF(SQL_TSI_YEAR, "Employee Personal Attributes"."Employee Birth Date", CURRENT_DATE) ELSE TIMESTAMPDIFF(SQL_TSI_YEAR, "Employee Personal Attributes"."Employee Birth Date", CURRENT_DATE)-1 END
VB FUNCTION:
Public Function AgeInYears(ByVal pvarBirthDate As Variant, ByVal pvarCompareDate As Variant) As Long
' Purpose: Calc age in years as of the compare date.
' Accepts: pvarBirthDate date
' pvarCompareDate date
' Returns: number
' Returns 0 if any needed fields blank.
On Error GoTo Err_AgeInYears
' Exit if some fields null.
If IsNull(pvarBirthDate) Or IsNull(pvarCompareDate) Then
AgeInYears = 0
Exit Function
End If
If (Month(pvarBirthDate) < Month(pvarCompareDate)) Or (Month(pvarBirthDate) = Month(pvarCompareDate) And Day(pvarBirthDate) <= Day(pvarCompareDate)) Then
AgeInYears = DateDiff("yyyy", pvarBirthDate, pvarCompareDate)
Else
AgeInYears = DateDiff("yyyy", pvarBirthDate, pvarCompareDate) - 1
End If
Exit Function
Err_AgeInYears:
MsgBox "Error " & Err & "." & Chr(13) & Chr(10) & Chr(10) & Err.Description & ".", vbExclamation
Exit Function
End Function