I'm using dbplyr to query an SQL database. The important columns are AppointmentDateTime and PatientDOB.
I'm trying to filter the data by the age at appt time.
What I have seems to work fine, but it seems like there may be a better way.
Here is what I have:
mutate(ApptAge = AppointmentDateTime - PatientDOB) %>%
filter(ApptAge < "1919-01-01") %>%
collect()
As you can see ApptAge is returned as a date (since 1900-01-01).
How could this be improved?
This also has an issue with leap-years, with the year since 1900 being impacted by those leap years which might be different than the number of leap years between the appointment and PatientDOB.
(My thought is that the code will be a lot more readable if I just pull in a bit extra from SQL, then determine the age using day/month combo then year to determine the age.)
I know there are many wiser than me here, so I just wondered if anyone had insights I could learn from.
Thanks,
Luke