#' Gets exact age
#'
#' Returns the exact age of a player given his birth date and some reference date. Idea from Alex Gable (\url{https://twitter.com/gableingaround}).
#'
#' @param from The start date. Typically the player's birth date.
#' @param to The reference date. Used for finding a player's draft eligibility, it's typically \code{2018-09-15}, or whatever the year of the NHL draft is.
#' @examples
#' get_years_difference("2000-09-15", "2018-09-15")
#'
#' # My birthday -- don't forget it!
#' get_years_difference("1995-10-22", "2018-08-27")
#'
#' @export
#' @import dplyr
#'
get_years_difference <- function(from, to) {
to <- suppressWarnings(lubridate::as_date(to))
from <- suppressWarnings(lubridate::as_date(from))
age <- lubridate::`%--%`(from, to) / lubridate::years(1)
return(age)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.