How to get Dates.Period without label?

Hot to get period like this : 16363320000 without label “milliseconds” ? Dates.period(t2-t1) not works…

(Julia 5.0)

julia> Dates.Period(t2-t1)
16363320000 milliseconds

julia> Dates.period(t2-t1)
ERROR: UndefVarError: period not defined

Paul

Dates.value(t2 - t1)
1 Like

Is possible to get it in minutes, hours, etc?
Paul

Dates.Minute(now()).value

Is that what you want?

Sorry but no:
julia> Dates.Minute(now()).value
24

julia> Dates.value(t2 - t1)
86399000

86399000 ms how many minutes ?
something like ths :slight_smile:

julia> Dates.Minute(t2 - t1).value
ERROR: InexactError()
in divexact(::Int64, ::Int64) at .\dates\periods.jl:3
in convert at .\dates\periods.jl:398 [inlined]
in Base.Dates.Minute(::Base.Dates.Millisecond) at .\s

Maybe this is what you’re looking for.

Dates.canonicalize(Dates.CompoundPeriod(t2-t1))

It is for Julia 0.6+ I think. Any reason you’re sticking with 0.5?

Thanks. i can use 6.0 !!! It Works

julia> Dates.canonicalize(Dates.CompoundPeriod(t2-t1))

23 hours, 59 minutes, 59 seconds

How to get separetly: h, m,s ? I need : h=23, m=59, s=59

h,m,s=Dates.canonicalize(Dates.CompoundPeriod(t2-t1))
julia> h,m,s=Dates.canonicalize(Dates.CompoundPeriod(t2-t1))
ERROR: MethodError: no method matching start(::Base.Dates.CompoundPeriod)
Closest candidates are:
start(::SimpleVector) at essentials.jl:258
start(::Base.MethodList) at reflection.jl:560
start(::ExponentialBackOff) at error.jl:107

Huh, I didn’t know it could do this until I tried.

julia> x = Dates.canonicalize(Dates.CompoundPeriod(t2-t1))
17 minutes, 18 seconds, 522 milliseconds

julia> x.periods
3-element Array{Base.Dates.Period,1}:
 17 minutes      
 18 seconds      
 522 milliseconds

julia> x.periods[2]
18 seconds

julia> x.periods[2].value
18

Big Thanks !!