# Average Number of Days (Convert Type Day to Number?)

**URL:** <https://discourse.julialang.org/t/average-number-of-days-convert-type-day-to-number/23172>\
**Category:** General Usage\
**Tags:** dates\
**Created:** [April 15, 2019, 8:31pm UTC](https://discourse.julialang.org/t/average-number-of-days-convert-type-day-to-number/23172 "2019-04-15T20:31:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [April 15, 2019, 8:31pm UTC](https://discourse.julialang.org/t/average-number-of-days-convert-type-day-to-number/23172/1 "2019-04-15T20:31:15Z")

</div>

Hello Julia Community,

I have an array of elements of type Day, and when attempting to compute the mean of that array with `mean(my_array_full_of_days)`, I get an InexactError because the result is a Float. Sum works just fine (as the return value is of type Day).

I tried converting the dates to Floats as well as simply rounding the return value of the sum function, but I get an error. Does anyone know what the cleanest solution to this problem is?

Thanks!!

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [April 15, 2019, 8:35pm UTC](https://discourse.julialang.org/t/average-number-of-days-convert-type-day-to-number/23172/2 "2019-04-15T20:35:15Z")

</div>

This always happens to me, I found a (somewhat ugly) solution like 2 minutes after posting the question:

I can compute the mean manually by using `Dates.value(sum(my_array_full_of_days)) / length(my_array_full_of_days)`

It sure would be nice to be able to just do `mean(my_array_full_of_days)` !!

---

<div class="post-metadata">

**Author:** ![ElOceanografo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eloceanografo/32/624_2.png) [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)\
**Post date:** [April 15, 2019, 9:05pm UTC](https://discourse.julialang.org/t/average-number-of-days-convert-type-day-to-number/23172/3 "2019-04-15T21:05:16Z")

</div>

How about `mean(Dates.value.(my_array_full_of_days))`?

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [April 15, 2019, 9:33pm UTC](https://discourse.julialang.org/t/average-number-of-days-convert-type-day-to-number/23172/4 "2019-04-15T21:33:23Z")

</div>

Awesome, I knew the awesome community here would come up with something better!
