Skip to content

Instantly share code, notes, and snippets.

@harunorimurata
Last active March 12, 2025 08:17
Show Gist options
  • Save harunorimurata/af968c20a706c2a1e50d1108304b5eb0 to your computer and use it in GitHub Desktop.
Save harunorimurata/af968c20a706c2a1e50d1108304b5eb0 to your computer and use it in GitHub Desktop.
// CalcAgeAt calculates the age at the given time.
func CalcAgeAt(t time.Time, birthDay time.Time) int {
age := t.Year() - birthDay.Year()
if t.YearDay() < birthDay.YearDay() {
age--
}
return age
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment