# Converting a Time() to an standardized Int64 or Float64

**URL:** <https://discourse.julialang.org/t/converting-a-time-to-an-standardized-int64-or-float64/65404>\
**Category:** Data\
**Tags:** dates\
**Created:** [July 27, 2021, 9:51pm UTC](https://discourse.julialang.org/t/converting-a-time-to-an-standardized-int64-or-float64/65404 "2021-07-27T21:51:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [July 27, 2021, 9:51pm UTC](https://discourse.julialang.org/t/converting-a-time-to-an-standardized-int64-or-float64/65404/1 "2021-07-27T21:51:05Z")

</div>

Hello Everyone:

I instantiated a variable using

```julia
Sprints = Time(00,01,00):Dates.Minute(1):Time(01,00,00)

```

and created a data frame with:

```julia
Allstars = DataFrame(Id = 1:10, BestTimes = rand(Sprints, 10))

```

How could I convert items in :BestTimes to  
standardized Int64 or Float64()?

Would you approach this doing something like:

```julia
DF = :BestTimes.value(Dates.minutes(5))
then
convert.(DF, Int64)

```

??

How would I manage zeros?

Thank you,

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 27, 2021, 11:53pm UTC](https://discourse.julialang.org/t/converting-a-time-to-an-standardized-int64-or-float64/65404/2 "2021-07-27T23:53:49Z")

</div>

Hi, the following creates a column with integer seconds:

```julia
using Dates, DataFrames

Sprints = Time(00,01,00):Dates.Minute(1):Time(01,00,00)
Allstars = DataFrame(Id = 1:10, BestTimes = rand(Sprints, 10))

Allstars[:,:IntBestTimes] = round.(Int64, Dates.value.(Allstars[:,:BestTimes])/1e9)

julia> Allstars
10×3 DataFrame
 Row │ Id BestTimes IntBestTimes 
     │ Int64 Time Int64        
─────┼────────────────────────────────
   1 │ 1 00:16:00 960
   2 │ 2 00:59:00 3540
   3 │ 3 00:18:00 1080
   4 │ 4 00:10:00 600
   5 │ 5 00:54:00 3240
   6 │ 6 00:12:00 720
   7 │ 7 00:08:00 480
   8 │ 8 00:29:00 1740
   9 │ 9 00:33:00 1980
  10 │ 10 00:07:00 420

```

or to get seconds as Float64:

```julia
Allstars[:,:FloatBestTimes] = Dates.value.(Allstars[:,:BestTimes])/1e9

```

---

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [July 28, 2021, 8:00am UTC](https://discourse.julialang.org/t/converting-a-time-to-an-standardized-int64-or-float64/65404/3 "2021-07-28T08:00:55Z")

</div>

@rafael.guerra Thank you – worked.

If I wanted to convert the Int or Float columns  
to minutes would I:

```julia
Allstars[:,:FloatBestTimes] = Dates.minute.(Allstars[:,:BestTimes])

```

Two follow-up question:

1. From what baseline are you deriving 1e9?
2. Why does 'round.Float64, Dates.value…)  
return a no method matching? Is there some  
logic or performance issue with this?

Thank you,

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 28, 2021, 8:14am UTC](https://discourse.julialang.org/t/converting-a-time-to-an-standardized-int64-or-float64/65404/4 "2021-07-28T08:14:13Z")

</div>

Hi, for the first question, from the doc: `Time` wraps a `Nanosecond` and represents a specific moment in a 24-hour day. So the baseline are nanoseconds.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 28, 2021, 8:19am UTC](https://discourse.julialang.org/t/converting-a-time-to-an-standardized-int64-or-float64/65404/5 "2021-07-28T08:19:35Z")

</div>

For the second question, rounding a Float64 to a Float64 (does not seem very useful) and it is not defined in Julia:

```julia
julia> round(Float64, 1.2)
ERROR: MethodError: no method matching round(::Type{Float64}, ::Float64)

```

The language experts will need to explain this.

---

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [July 28, 2021, 8:23am UTC](https://discourse.julialang.org/t/converting-a-time-to-an-standardized-int64-or-float64/65404/6 "2021-07-28T08:23:17Z")

</div>

@rafael.guerra

I meant:

```julia
round.(Int64, Dates.value.(Allstars[:,:BestTimes])/1e9)

```

To:

```julia
round.(Float64, Dates.value.(Allstars[:,:BestTimes])/1e9)

```

The :BestTimes attribute is a Float64 implicitly?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 28, 2021, 8:28am UTC](https://discourse.julialang.org/t/converting-a-time-to-an-standardized-int64-or-float64/65404/7 "2021-07-28T08:28:43Z")

</div>

We have integers:

```julia
Dates.value.(Allstars[:,:BestTimes])

```

that get promoted to floats after division by `1e9`. So your line of code is trying to round Float64 to Float64.

---

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [July 28, 2021, 9:11am UTC](https://discourse.julialang.org/t/converting-a-time-to-an-standardized-int64-or-float64/65404/8 "2021-07-28T09:11:06Z")

</div>

@rafael.guerra Thanks for clarifying.
