datetimejuliadatetime-formatdataframes.jl

Convert String31 datetime format into datetime in Julia


i have a dataframe with Time colume with String31 format. How can I convert this foramt into datetime?

Image

I use Datetime method but it raised an error::

str_1=data_raw.Time[1,:]
DateTime(str_1, "yyyymmdd HHMMSS")

Error:

MethodError: no method matching Int64(::Vector{String31})
Closest candidates are:
(::Type{T})(!Matched::AbstractChar) where T<:Union{Int32, Int64}
@ Base char.jl:51
(::Type{T})(!Matched::AbstractChar) where T<:Union{AbstractChar, Number}
@ Base char.jl:50
(::Type{T})(!Matched::BigInt) where T<:Union{Int128, Int16, Int32, Int64, Int8}
@ Base gmp.jl:36

Solution

  • Do:

    DateTime.(str_1, "yyyy-mm-dd HH:MM:SS")
    

    (note the . before ( - it broadcasts DateTime over all elements of str_1)