package main
import (
"fmt"
"strconv"
"time"
)
func findAge(birthday string) int {
dateFormat := "02/01/2006"
dob, err := time.Parse(dateFormat, birthday)
if err != nil {
panic(err)
}
var age int
age = time.Now().Year() - dob.Year()
month, _ := strconv.Atoi(strconv.Itoa(dob.Day()) + strconv.Itoa(int(dob.Month())))
day, _ := strconv.Atoi(strconv.Itoa(time.Now().Day()) + strconv.Itoa(int(time.Now().Month())))
if month > day {
age -= 1
}
return age
}
func main() {
dob := "16/05/2001"
age := findAge(dob)
fmt.Println("age:", age)
}
age: 21