# Simple method for converting float array to DateTime (or similar)?

**URL:** https://discourse.julialang.org/t/simple-method-for-converting-float-array-to-datetime-or-similar/71621
**Category:** New to Julia
**Tags:** dates
**Created:** [November 16, 2021, 10:59pm UTC](https://discourse.julialang.org/t/simple-method-for-converting-float-array-to-datetime-or-similar/71621 "2021-11-16T22:59:43Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![ToddAnderson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/toddanderson/32/30826_2.png) [@ToddAnderson](https://discourse.julialang.org/u/ToddAnderson)
#### Post date: [November 17, 2021, 6:20pm UTC](https://discourse.julialang.org/t/simple-method-for-converting-float-array-to-datetime-or-similar/71621/6 "2021-11-17T18:20:14Z")

</div>

@rafael.guerra I like this one! Nice that you can easily get millisecond precision with `DateTime.(t)`, or preserve microsecond precision with `Date.(t)` and `Time.(t)`. So the full solution becomes:

```julia
using Dates, CompoundPeriods

T = [ 2017 09 06 00 00 04.911360;
        2017 09 06 04 15 55.193727;
        2017 09 06 22 55 12.256655]

tcp = Year.(T[:,1]) + Month.(T[:,2]) + Day.(T[:,3]) + Hour.(T[:,4]) +
      + Minute.(T[:,5]) + Nanosecond.(round.(Int,1e9*T[:,6]))

t = canonical.(tcp)

sdt = DateTime.(t) # millisecond precision
sdate = Date.(t) # date only
stime = Time.(t) # time only with microsecond precision

```

---

_[View the full topic](https://discourse.julialang.org/t/simple-method-for-converting-float-array-to-datetime-or-similar/71621)._
