DRY: How to simplify this duplicated code for date into a funciton?

how to use %in% in r
r functions cheat sheet
$ in r code
r functions list
dollar sign in r code
exclamation mark in r
r function return
r function arguments