# Issue when Converting object of Type day to year

**URL:** https://discourse.julialang.org/t/issue-when-converting-object-of-type-day-to-year/20560
**Category:** General Usage
**Tags:** dates
**Created:** [February 7, 2019, 7:40pm UTC](https://discourse.julialang.org/t/issue-when-converting-object-of-type-day-to-year/20560 "2019-02-07T19:40:40Z")
**Posts on this page:** 1
**Showing post:** 10

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [February 8, 2019, 7:13am UTC](https://discourse.julialang.org/t/issue-when-converting-object-of-type-day-to-year/20560/10 "2019-02-08T07:13:48Z")

</div>

Note that you cannot calculate the age of a person in years when you know their age in days. So your function will need to work on both dates and not on their difference:

```julia
julia> function age(dob, date)
       age = Dates.year(date)- Dates.year(dob) -1
       if Dates.month(date)>Dates.month(dob) || (Dates.month(date)==Dates.month(dob) && Dates.day(date)>=Dates.day(dob))
         age += 1
       end
       return age
       end

```

PS: have another read on how to quote your code: [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530)

---

_[View the full topic](https://discourse.julialang.org/t/issue-when-converting-object-of-type-day-to-year/20560)._
