# Why Does Julia Have Two Different Epoch Starts?

**URL:** https://discourse.julialang.org/t/why-does-julia-have-two-different-epoch-starts/9622
**Category:** General Usage
**Created:** [March 9, 2018, 11:15pm UTC](https://discourse.julialang.org/t/why-does-julia-have-two-different-epoch-starts/9622 "2018-03-09T23:15:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)
#### Post date: [March 9, 2018, 11:15pm UTC](https://discourse.julialang.org/t/why-does-julia-have-two-different-epoch-starts/9622/1 "2018-03-09T23:15:07Z")

</div>

```julia
julia> dt = DateTime(2004, 12, 31, 17, 30, 1)
2004-12-31T17:30:01

julia> convert( Int, dt )
63240197401000

julia> ep1= convert( Int, dt )
63240197401000

julia> ep2= Dates.datetime2epochms( dt )
63271733401000

julia> (ep1-ep2) /1000/60/60/24
-365.0

```

They differ by 1 year. One starts at 0001, the other at 0000. It’s somewhat confusing and easy to get wrong.

```julia
julia> Dates.epochms2datetime( convert( Int, Dates.now() ) )
2017-03-09T15:14:27.272

```

Ahem…mea culpa.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 10, 2018, 8:26am UTC](https://discourse.julialang.org/t/why-does-julia-have-two-different-epoch-starts/9622/2 "2018-03-10T08:26:25Z")

</div>

Which version of Julia are you using? You should have got this warning on `v0.6.2`:

```julia
julia> convert(Int, Dates.now())
WARNING: convert(::Type{R}, x::Dates.DateTime) where R <: Real is deprecated, use R(Dates.value(x)) instead.
Stacktrace:
 [1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
 [2] convert(::Type{Int64}, ::DateTime) at ./deprecated.jl:57
 [3] eval(::Module, ::Any) at ./boot.jl:235
 [4] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:66
 [5] macro expansion at /home/tamas/.julia/v0.6/Revise/src/Revise.jl:775 [inlined]
 [6] (::Revise.##17#18{Base.REPL.REPLBackend})() at ./event.jl:73
while loading no file, in expression starting on line 0
63656357005203

```

The lesson is that you should use the API provided for the purpose. There is literally nothing that suggests that `convert(::Type{Int}, ::Date)` should be used for calculating \Delta from the epoch.

---

<div class="post-metadata">

### Author: ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)
#### Post date: [March 10, 2018, 4:10pm UTC](https://discourse.julialang.org/t/why-does-julia-have-two-different-epoch-starts/9622/3 "2018-03-10T16:10:30Z")

</div>

yes, I did on the first try. I checked and then forgot about it. mea culpa.

```julia
julia> Dates.value(Dates.now()) - convert(Int, Dates.now())
0

```

the real issue is that two julia epoch ms seem like a bad idea to me, and the source for needless bugs and confusion in the future. if it were me, I would deprecate one of them. I did not file this as an issue, because I do not know whether there is another reasoning here that I am unaware of.

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [March 10, 2018, 5:26pm UTC](https://discourse.julialang.org/t/why-does-julia-have-two-different-epoch-starts/9622/4 "2018-03-10T17:26:20Z")

</div>

Yes, it’s quite understandable that you’d be confused here. Tamas’ message reads a little overly harshly to me — the fact that we had this inconsistently defined was our fault, not yours. But he’s also demonstrating that on 0.6.2, that conversion is indeed deprecated. I highly recommend you update to version 0.6.

On master this trap is gone entirely.

---

<div class="post-metadata">

### Author: ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)
#### Post date: [March 10, 2018, 5:43pm UTC](https://discourse.julialang.org/t/why-does-julia-have-two-different-epoch-starts/9622/6 "2018-03-10T17:43:45Z")

</div>

version 0.6.2:

```julia
julia> dt= Dates.now()
2018-03-10T09:40:53.757

julia> ep1, ep2= Dates.value( dt ), Dates.datetime2epochms( dt )
(63656358053757, 63687894053757)

julia> (ep2-ep1) /1000/60/60/24
365.0

```

I will file an issue. regards, /iaw
