# DateTime bug - Julia 0.6RC3

**URL:** https://discourse.julialang.org/t/datetime-bug-julia-0-6rc3/4278
**Category:** General Usage
**Created:** [June 14, 2017, 9:45pm UTC](https://discourse.julialang.org/t/datetime-bug-julia-0-6rc3/4278 "2017-06-14T21:45:30Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![js135005](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/js135005/32/8219_2.png) [@js135005](https://discourse.julialang.org/u/js135005)
#### Post date: [June 14, 2017, 9:45pm UTC](https://discourse.julialang.org/t/datetime-bug-julia-0-6rc3/4278/1 "2017-06-14T21:45:30Z")

</div>

There appears to be a bug(s) in the implementation of DateTime functions in Julia 0.6RC3 as shown below:

```
           _

```

\_ \_ _(_)\_ | A fresh approach to technical computing  
(_) | (_) (_) | Documentation: [https://docs.julialang.org](https://docs.julialang.org)  
\_ \_ | | \_\_ \_ | Type “?help” for help.  
| | | | | | |/ ` | |  
| | || | | | (_| | | Version 0.6.0-rc3.0 (2017-06-07 11:53 UTC)  
_/ |\ __‘_|_|_|\__ ’\_| | Official [http://julialang.org/](http://julialang.org/) release  
|\_\_/ | x86\_64-w64-mingw32

julia\> dtnow=now()  
2017-06-14T17:23:31.434

julia\> dtnval=Dates.value(dtnow)  
63633144211434

julia\> dtnback=Dates.epochms2datetime(dtnval)  
2016-06-14T17:23:31.434

julia\> dtbase=DateTime(0)  
0000-01-01T00:00:00

julia\> dtbval=Dates.value(dtbase)  
-31536000000

Clearly the epoch base was chosen as 0001-01-01T00:00:00 rather than 0000-01-01T00:00:00 as stated in the stdlib manual.

I would have raised an issue about this had I been able to figure out how to do so - being very new on github. Nevertheless I certainly would not have expected conversion and back conversion to have been off by a full year!

John Sutherland

---

<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: [June 15, 2017, 5:20am UTC](https://discourse.julialang.org/t/datetime-bug-julia-0-6rc3/4278/2 "2017-06-15T05:20:56Z")

</div>

Isn’t this just a mistake in the documentation then? It would be easy to submit a PR for that.

Also, please use code fences (```julia … ```) to format your code.

---

<div class="post-metadata">

### Author: ![js135005](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/js135005/32/8219_2.png) [@js135005](https://discourse.julialang.org/u/js135005)
#### Post date: [June 15, 2017, 11:48am UTC](https://discourse.julialang.org/t/datetime-bug-julia-0-6rc3/4278/3 "2017-06-15T11:48:17Z")

</div>

No it is not just a documentation problem. The code snippet

```julia
dt=now()
Dates.epochms2datetime(Dates.value(dt))

```

should return the original date/time rather than 1 year earlier.

This is a very simple usecase that should be added to the test suite.

Thanks for telling me about the code fences.

---

<div class="post-metadata">

### Author: ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)
#### Post date: [June 15, 2017, 12:53pm UTC](https://discourse.julialang.org/t/datetime-bug-julia-0-6rc3/4278/4 "2017-06-15T12:53:55Z")

</div>

Maybe this solves the conundrum:

```julia
julia> dtbase=DateTime(Dates.UTM(0))
0000-12-31T00:00:00

julia> dtbval=Dates.value(dtbase)
0

```

Don’t ask me to explain the `UTM`. In general, I think there is a whole level of hell dedicated to time zones.

---

<div class="post-metadata">

### Author: ![js135005](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/js135005/32/8219_2.png) [@js135005](https://discourse.julialang.org/u/js135005)
#### Post date: [June 15, 2017, 1:36pm UTC](https://discourse.julialang.org/t/datetime-bug-julia-0-6rc3/4278/5 "2017-06-15T13:36:27Z")

</div>

From the documentation, we see this:

‘’’  
As Julia Date and DateTime values are represented according to the ISO 8601 standard, 0000-01-01T00:00:00 was chosen as base (or “rounding epoch”) from which to begin the count of days (and milliseconds) used in rounding calculations. (Note that this differs slightly from Julia’s internal representation of Date s using Rata Die notation; but since the ISO 8601 standard is most visible to the end user, 0000-01-01T00:00:00 was chosen as the rounding epoch instead of the 0000-12-31T00:00:00 used internally to minimize confusion.)  
‘’’

Even if what I got actually is intended behaviour, I still feel there should be a function that back converts a datetime value to its original state. In my code, I’ve used the simple expedient of subtracting Dates.value(DateTime(0)) from the datetime value to be converted before calling the Dates.epochms2datetime function. However using different epoch and internal rounding values certainly does not minimize confusion!

---

<div class="post-metadata">

### Author: ![js135005](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/js135005/32/8219_2.png) [@js135005](https://discourse.julialang.org/u/js135005)
#### Post date: [June 17, 2017, 1:03pm UTC](https://discourse.julialang.org/t/datetime-bug-julia-0-6rc3/4278/6 "2017-06-17T13:03:50Z")

</div>

On the assumption this is actually intended behaviour and not a bug, the documentation definitely needs to be updated to clarify the usage of function Dates.epochms2datetime.

My workaround is to subtract Dates.value(DateTime(0)) from my date time values before backconversion.

---

<div class="post-metadata">

### Author: ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)
#### Post date: [October 11, 2017, 6:39pm UTC](https://discourse.julialang.org/t/datetime-bug-julia-0-6rc3/4278/7 "2017-10-11T18:39:45Z")

</div>

Realy, is not to cleary :

julia\> T=Array{DateTime}(1)  
1-element Array{DateTime,1}:  
0000-12-31T00:00:00

julia\> Dates.value.(T)  
1-element Array{Int64,1}:  
0  
What to calculate time with this ?  
Paul
