{"id":1209,"date":"2020-01-23T16:36:42","date_gmt":"2020-01-23T16:36:42","guid":{"rendered":"https:\/\/golangbyexamples.com\/?p=1209"},"modified":"2020-01-24T03:06:46","modified_gmt":"2020-01-24T03:06:46","slug":"get-age-given-dob-go","status":"publish","type":"post","link":"https:\/\/golangbyexamples.com\/get-age-given-dob-go\/","title":{"rendered":"Get age given a DOB in Go (Golang)"},"content":{"rendered":"\n
This tutorial will talk about how given a date of birth we can compute the age of a person. go-age<\/strong> comes to our rescue for doing that. It also takes into account the complexities of leap year while calculating age. See a below working example:<\/p>\n\n\n\n Output:<\/strong><\/p>\n\n\n\n This tutorial will talk about how given a date of birth we can compute the age of a person. go-age comes to our rescue for doing that. It also takes into account…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[170,4],"class_list":["post-1209","post","type-post","status-publish","format-standard","hentry","category-tech","tag-age","tag-golang"],"yoast_head":"\n
<\/p>\n\n\n\npackage main\n\nimport (\n \"fmt\"\n \"time\"\n age \"github.com\/bearbin\/go-age\"\n)\n\nfunc main() {\n dob := getDOB(2011, 4, 2)\n fmt.Printf(\"Age is %d\\n\", age.Age(dob))\n}\n\nfunc getDOB(year, month, day int) time.Time {\n dob := time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC)\n return dob\n}<\/code><\/pre>\n\n\n\n
Age is 8<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"