Created
April 25, 2021 14:33
-
-
Save mehmetsefabalik/84290f4892cc5eb8df7ba974e75f349a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use chrono; | |
use chrono::offset::TimeZone; | |
let birth_date = chrono::Utc.from_local_date(&chrono::NaiveDate::parse_from_str("1995-07-05", "%Y-%m-%d")).unwrap(); | |
let duration_since_birth = chrono::Utc::today().signed_duration_since(birth_date); | |
let age = duration_since_birth.num_days() / 365 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You forgot to
unwrap()
the Result,from_local_date
expects a&NaiveDate