Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehmetsefabalik/84290f4892cc5eb8df7ba974e75f349a to your computer and use it in GitHub Desktop.
Save mehmetsefabalik/84290f4892cc5eb8df7ba974e75f349a to your computer and use it in GitHub Desktop.
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
@simanacci
Copy link

You forgot to unwrap() the Result, from_local_date expects a &NaiveDate

fn from_local_date(&self, local: &NaiveDate) -> LocalResult<Date<Self>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment