# Cannot convert Time to Time

**URL:** <https://discourse.julialang.org/t/cannot-convert-time-to-time/129207>\
**Category:** General Usage\
**Tags:** datetime\
**Created:** [May 21, 2025, 9:26am UTC](https://discourse.julialang.org/t/cannot-convert-time-to-time/129207 "2025-05-21T09:26:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [May 21, 2025, 9:26am UTC](https://discourse.julialang.org/t/cannot-convert-time-to-time/129207/1 "2025-05-21T09:26:53Z")

</div>

Any idea what`s happening?

```julia
julia> s = "18:59:00"
"18:59:00"

julia> t0 = Time(s)
18:59:00

julia> t = Time(t0)
ERROR: MethodError: no method matching Int64(::Time)
The type `Int64` exists, but no method is defined for this combination of argument types when trying to construct it.

```

For comparison, no problems like this with `Date` or `DateTime`:

```julia
julia> sd = "2025-05-15T18:59:00"
"2025-05-15T18:59:00"

julia> d0 = DateTime(sd)
2025-05-15T18:59:00

julia> d = DateTime(d0)
2025-05-15T18:59:00

```

The background: I’ve array of mixed `DateTime` / `Time` and wanted to strip the `Date` part. Sure, there are easy workarounds… after being driven crazy by the error

---

<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:** [May 21, 2025, 9:37am UTC](https://discourse.julialang.org/t/cannot-convert-time-to-time/129207/2 "2025-05-21T09:37:18Z")

</div>

Shorter:

```julia
julia> Date(Date(0))
0000-01-01

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

julia> Time(Time(0))
ERROR: MethodError: no method matching Int64(::Time)

```

That constructor just isn’t defined so it falls back to the generic single-arg `Time(h)` constructor which calls `Time(Int64(h)...)` hence the error.

Seems like that might be reasonable to add, check if there’s an issue on the Dates repo and open one if there isn’t?

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [May 21, 2025, 9:48am UTC](https://discourse.julialang.org/t/cannot-convert-time-to-time/129207/3 "2025-05-21T09:48:36Z")

</div>

> [@nilshg](#):
>
> check if there’s an issue on the Dates repo and open one if there isn’t?

would do it

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [May 21, 2025, 10:23am UTC](https://discourse.julialang.org/t/cannot-convert-time-to-time/129207/4 "2025-05-21T10:23:26Z")

</div>

It’s worth reminding that the API for conversion is `convert`, and when the target type is already met, it falls back to returning the input like `identity`. Constructors however are intended for instantiation, so when the input matches the target type, it tends to be _cloned_. A rough rule for instantiation returning the input is when cloning an immutable type would result in the same instance anyway, or if the API is immutable so we shouldn’t rely on the mutable type’s identity e.g. `BigInt`. For example, `x = 3; Integer(x) === x` returns `true`. For a counterexample, `x = [3]; Vector(x) === x` returns `false`. There are also cases where instantiation wouldn’t clone; for example, `Ref(Ref(1))` adds a 2nd layer of reference.

`Time` is immutable so `Time(x::Time) = x` is reasonable, but it’s best to use `convert` when your program strictly needs to convert (which it may not).
