# Converting dates to excel compatible

**URL:** <https://discourse.julialang.org/t/converting-dates-to-excel-compatible/100022>\
**Category:** General Usage\
**Created:** [June 7, 2023, 8:08pm UTC](https://discourse.julialang.org/t/converting-dates-to-excel-compatible/100022 "2023-06-07T20:08:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pino](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@Pino](https://discourse.julialang.org/u/Pino)\
**Post date:** [June 7, 2023, 8:08pm UTC](https://discourse.julialang.org/t/converting-dates-to-excel-compatible/100022/1 "2023-06-07T20:08:47Z")

</div>

I use dates in julia, then I convert them in days in the following fashion

```julia
# Convert a date to a number of days
date = Date(2023, 6, 7)
days = Dates.days(date)
println(days)
738678

```

I then look up the dates with other values to create an array that I want to export in excel. My issue is that dates are then in the julia format above (i.e. in actual number of dates)

Is there a way to convert `days` back into a date that I can use in excel?

---

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [June 8, 2023, 6:01pm UTC](https://discourse.julialang.org/t/converting-dates-to-excel-compatible/100022/2 "2023-06-08T18:01:10Z")

</div>

There are apparently [two formats](https://support.microsoft.com/en-us/office/date-systems-in-excel-e7fe7167-48a9-4b96-bb53-5612a800b487), do you know which Excel format?

---

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [June 8, 2023, 7:41pm UTC](https://discourse.julialang.org/t/converting-dates-to-excel-compatible/100022/3 "2023-06-08T19:41:20Z")

</div>

So the `Dates.days` function seems to reference to year 1, January 1. Microsoft seems to use the 1904 system? The difference in days is then:

```julia
julia> Dates.days(Date("0001-01-01"))
1

julia> Dates.days(Date("1904-01-01"))
695056

```

---

<div class="post-metadata">

**Author:** ![Pino](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@Pino](https://discourse.julialang.org/u/Pino)\
**Post date:** [June 9, 2023, 12:37pm UTC](https://discourse.julialang.org/t/converting-dates-to-excel-compatible/100022/4 "2023-06-09T12:37:43Z")

</div>

Newer versions of excel use 1900 as a base year. I can do the difference in dates then and see. I was wondering if there’s a more immediate way to work with dates in julia. Coming from matlab I never did bother that much working with arrays of time which I could easily use in excel.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 9, 2023, 12:44pm UTC](https://discourse.julialang.org/t/converting-dates-to-excel-compatible/100022/5 "2023-06-09T12:44:14Z")

</div>

What do you mean by “more immediate way”? Why not just write the Dates to Excel?

```julia
julia> using XLSX, Dates

julia> XLSX.writetable("out.xlsx", (x = Date(2010):Year(1):Date(2019), y = rand(10)))

```

gives:

![image](https://global.discourse-cdn.com/julialang/original/3X/d/a/da0722b6f8562e2063188655d58b8926c4fee72a.png)

Or is your question about how to get the date back from `738678` in Julia?

```julia
julia> Dates.epochdays2date(738678) + Year(1)
2023-06-07

```
