# Differences smaller than Dates.Milliseconds are ignored

**URL:** https://discourse.julialang.org/t/differences-smaller-than-dates-milliseconds-are-ignored/26068
**Category:** Internals & Design
**Tags:** question, bug, dates
**Created:** [July 6, 2019, 11:52am UTC](https://discourse.julialang.org/t/differences-smaller-than-dates-milliseconds-are-ignored/26068 "2019-07-06T11:52:24Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [July 6, 2019, 11:52am UTC](https://discourse.julialang.org/t/differences-smaller-than-dates-milliseconds-are-ignored/26068/1 "2019-07-06T11:52:25Z")

</div>

I have a really hard time understanding this:

```julia
julia> using Dates

julia> dt1 = DateTime(1)
0001-01-01T00:00:00

julia> for timeperiod in (Hour, Minute, Second, Millisecond, Microsecond, Nanosecond)
           dt2 = dt1 + oneunit(timeperiod)
           @show dt1 ≠ dt2
       end
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = false
dt1 ≠ dt2 = false

```

Why are differences smaller than milliseconds ignored…? Has this been extensively covered somewhere…?

---

<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: [July 6, 2019, 12:08pm UTC](https://discourse.julialang.org/t/differences-smaller-than-dates-milliseconds-are-ignored/26068/2 "2019-07-06T12:08:52Z")

</div>

The underlying integer simply cannot represent that kind of a precision. Cf

```julia
using Dates
d = DateTime(1)
d2 = d + oneunit(Microsecond)
d.instant.periods.value == d2.instant.periods.value

```

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [July 6, 2019, 12:10pm UTC](https://discourse.julialang.org/t/differences-smaller-than-dates-milliseconds-are-ignored/26068/3 "2019-07-06T12:10:23Z")

</div>

OK, so I think I understand why it doesn’t work.

```julia
help?> DateTime
search: DateTime datetime2unix datetime2rata datetime2julian ISODateTimeFormat unix2datetime

  DateTime

  DateTime wraps a UTInstant{Millisecond} and interprets it according to the proleptic Gregorian
  calendar.

```

But man, I can’t help think that it’s misleading to be able to add a Nanosecond, in fact `10^6 - 1` of them without noticing any difference. Hmm…

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [July 6, 2019, 12:13pm UTC](https://discourse.julialang.org/t/differences-smaller-than-dates-milliseconds-are-ignored/26068/4 "2019-07-06T12:13:00Z")

</div>

Like, if I want to be able to do arithmetic on `DateTime` _and_`Nanosecond` I guess I should convert everything to `Millisecond`s…

---

<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: [July 6, 2019, 12:13pm UTC](https://discourse.julialang.org/t/differences-smaller-than-dates-milliseconds-are-ignored/26068/5 "2019-07-06T12:13:23Z")

</div>

> [@yakir12](#):
>
> it’s misleading to be able to add a Nanosecond, in fact `10^6 - 1` of them without noticing any difference

Cf

```julia
julia> 1.0 + eps()/2
1.0

```

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [July 6, 2019, 12:13pm UTC](https://discourse.julialang.org/t/differences-smaller-than-dates-milliseconds-are-ignored/26068/6 "2019-07-06T12:13:47Z")

</div>

Touché…

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [July 6, 2019, 12:15pm UTC](https://discourse.julialang.org/t/differences-smaller-than-dates-milliseconds-are-ignored/26068/7 "2019-07-06T12:15:16Z")

</div>

> [@Tamas\_Papp](#):
>
> julia\> 1.0 + eps()/2 1.0

That is a really good point. OK. I’ll deal. Thanks again @Tamas_Papp!!!

---

<div class="post-metadata">

### Author: ![hellemo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hellemo/32/324_2.png) [@hellemo](https://discourse.julialang.org/u/hellemo)
#### Post date: [July 6, 2019, 4:20pm UTC](https://discourse.julialang.org/t/differences-smaller-than-dates-milliseconds-are-ignored/26068/8 "2019-07-06T16:20:10Z")

</div>

You could give [TimesDates.jl](https://github.com/JeffreySarnoff/TimesDates.jl) a shot:

```julia
julia> using TimesDates,Dates

julia> dt1 = TimeDate(1)
0001-01-01T00:00:00

julia> for timeperiod in (Hour, Minute, Second, Millisecond, Microsecond, Nanosecond)
                  dt2 = dt1 + oneunit(timeperiod)
                  @show dt1 ≠ dt2
              end
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true

```
