# Define zero for DateTime

**URL:** https://discourse.julialang.org/t/define-zero-for-datetime/6035
**Category:** Internals & Design
**Tags:** question, proposal
**Created:** [September 22, 2017, 11:49am UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035 "2017-09-22T11:49:29Z")
**Posts on this page:** 17
**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: [September 22, 2017, 11:49am UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/1 "2017-09-22T11:49:29Z")

</div>

Do you even…?

More seriously, it would be useful if we could treat time like any other quantity. Everyone seems to agree that the world started either `now()` ago, or on `00:00 1st January 1970`. Not sure what convention other languages use nor why, but it would be great if we could pick one and move on.

---

<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: [September 22, 2017, 12:34pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/2 "2017-09-22T12:34:50Z")

</div>

Do you need it for [arithmetic](https://docs.julialang.org/en/latest/manual/dates/#TimeType-Period-Arithmetic-1)? `Dates.Day(0)` would do for most purposes I can imagine.

---

<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: [September 22, 2017, 1:18pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/3 "2017-09-22T13:18:44Z")

</div>

I just discovered the excellent [IntervalTrees.jl](https://github.com/BioJulia/IntervalTrees.jl). If we were to use it to define intervals based on dates (a reasonable case), then it errors on the inability to get a zero from a `DateTime`. Got me thinking…

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [September 22, 2017, 2:01pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/4 "2017-09-22T14:01:49Z")

</div>

By the way, I find it very strange that `DateTime()` gives you 0001-01-01T00:00:00 even though the actual value of `DataTime()` in milliseconds is `1000*60*60*24`. I also don’t understand why either one of these dates should be zero. It would make far more sense if `0000-01-01T00:00:00` were zero. Is this based on some standard?

---

<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: [September 22, 2017, 2:04pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/5 "2017-09-22T14:04:03Z")

</div>

Agreed.

---

<div class="post-metadata">

### Author: ![Evey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evey/32/214967_2.png) [@Evey](https://discourse.julialang.org/u/Evey)
#### Post date: [September 23, 2017, 8:24am UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/6 "2017-09-23T08:24:15Z")

</div>

Does it make sense to add dates? `zero` is the additive identity, i. e., it must hold that `a + zero(a) == a`. It seems to me that it only makes sense if there is such a thing as a relative date. Maybe a bit unrelated, but this highlights an issue that I have run into recently, where some code (also in base) relies on `zero` and `one` to do type promotion (notably `inv(::AbstractArray)`). In this case, a relative date would be of a different type than an absolute date.

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [September 23, 2017, 8:52am UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/7 "2017-09-23T08:52:48Z")

</div>

There is no year zero as 1BC is followed by 1AD: [Year zero - Wikipedia](https://en.wikipedia.org/wiki/Year_zero). Well, at least in the BC/AD system, however, `DateTime(0)` works.

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [September 23, 2017, 11:57am UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/8 "2017-09-23T11:57:36Z")

</div>

`zero(::Date) = Day(0)` would make sense. `Month(0)` and `Year(0)` would also be correct, but it’s more logical to use the smallest unit.

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [September 25, 2017, 1:28pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/9 "2017-09-25T13:28:59Z")

</div>

Well, I don’t know what Pope Gregory would have to say about this, but according to Julia’s `DateTime` there is most definitely a year 0:

```julia
julia> DateTime() - Dates.Year(1)
0000-01-01T00:00:00

```

(Yes, we are using a system of measurement created by edict of the pope in the 16th century. The horror.)

---

<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: [September 25, 2017, 2:25pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/10 "2017-09-25T14:25:00Z")

</div>

I think the way forward (in all dimensions) is to just choose a reference point. This is strongly related to weather we should allow negative dates as well…  
Time is a dimension. We can have a reference point, zero, and negative values for all 3 spatial axes. Why not time as well?

---

<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: [September 25, 2017, 2:50pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/11 "2017-09-25T14:50:13Z")

</div>

> **[Astronomical year numbering](https://en.wikipedia.org/wiki/Astronomical_year_numbering)**
>
> Astronomical year numbering is based on AD/CE year numbering, but follows normal decimal integer numbering more strictly. Thus, it has a year 0; the years before that are designated with negative numbers and the years after that are designated with positive numbers. Astronomers use the Julian calendar for years before 1582, including the year 0, and the Gregorian calendar for years after 1582, as exemplified by Jacques Cassini (1740), Simon Newcomb (1898) and Fred Espenak (2007).
> The prefix AD ...

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [September 25, 2017, 3:07pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/12 "2017-09-25T15:07:33Z")

</div>

Having a zero year in terms of presentation is very different from having a zero moment in terms of representation (i.e. epoch). Julia is _very_ good at separating representation and behavior without sacrificing usability or performance, so let’s not make Matlab’s mistake here and try to make the year zero the epoch just because it seems like the “right” epoch. – that would mean that if we do allow using `Float64` to represent datetimes we would have amazing precision around the birthdate of some historical dude and terribly precision around today.

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [September 25, 2017, 3:59pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/13 "2017-09-25T15:59:27Z")

</div>

Well, ok, but then why set the epoch to zero on that particular date? It is still a couple of thousand years ago, so one still needs to tack on a few orders of magnitude to get to modern times. Why not simply conform to Unix time? That seems like the best option to me.

---

<div class="post-metadata">

### Author: ![tuckermcclure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tuckermcclure/32/1187_2.png) [@tuckermcclure](https://discourse.julialang.org/u/tuckermcclure)
#### Post date: [September 25, 2017, 4:21pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/14 "2017-09-25T16:21:19Z")

</div>

One option is to allow date functions to have an input to specify the epoch. For instance, a user could pass in `:unix_epoch` (maybe this is a default) or `:j2000_epoch` or `:gps_epoch` or `:matlab_epoch`. This is done in some geophysical software where both elapsed time and dates are important. It removes ambiguity and allows a user to place precision where it’s important to them. On the other hand, I can’t tell if this is a solution so broad that it satisfies everybody or if it’s a solution so broad that it satisfies nobody.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [September 25, 2017, 4:49pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/15 "2017-09-25T16:49:14Z")

</div>

@ExpandingMan, I can’t tell if you’re replying to me or not. I’m saying that we should _not_ use some ancient date as an epoch. 1970 is recent enough to be a good epoch. Supporting different epochs would be an interesting possibility (not too hard in Julia), but I’m not sure it would be worth the effort.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [September 25, 2017, 4:49pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/16 "2017-09-25T16:49:52Z")

</div>

It would make much more sense to me to have that be part of the time type, not an input parameter.

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [September 25, 2017, 5:42pm UTC](https://discourse.julialang.org/t/define-zero-for-datetime/6035/17 "2017-09-25T17:42:28Z")

</div>

Oh. I was confused because since _currently_ t=0 corresponds to `0001-01-01T00:00:00` I had assumed that there was some consensus in regard to that. In that case it sounds like we are in agreement, there seems to be no reason to use anything other than unix time.
