# Datetimes and SQLite.jl encoding

**URL:** https://discourse.julialang.org/t/datetimes-and-sqlite-jl-encoding/16412
**Category:** General Usage
**Created:** [October 16, 2018, 3:32pm UTC](https://discourse.julialang.org/t/datetimes-and-sqlite-jl-encoding/16412 "2018-10-16T15:32:28Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mosiman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mosiman/32/6959_2.png) [@mosiman](https://discourse.julialang.org/u/mosiman)
#### Post date: [October 16, 2018, 3:32pm UTC](https://discourse.julialang.org/t/datetimes-and-sqlite-jl-encoding/16412/1 "2018-10-16T15:32:28Z")

</div>

Hey all, hopefully this is the right place to post this question since I have no idea if its a lack of my own knowledge, or SQLite.jl, SQLite, or encodings in general.

I did some work a while ago in Julia, and used the SQLite.jl package to save my results, one of the columns storing a DateTime object.

I’m now trying to use this SQLite database with Python, but I can’t seem to decode the datetime part.

This is what python sees:

```julia
b'7JL\x07\x04\x00\x00\x004\x10\x01\nSerialized\x1f\x0b\xd9\x94\xf2J\xc2k"\xa7\xf4_r\xb0\xcd\x19\xa8\n\x01\x06SQLiteD4\x10\x01\x08DateTime\x1f\x0bj\xe02\x94\t\xdc\xfb\x98EY\x918p\xca\xe2\xad\x01\x05DatesD4\x10\x01\tUTInstant\x1f\x0bj\xe02\x94\t\xdc\xfb\x98EY\x918p\xca\xe2\xad\x01\x05DatesD\x01\x00\x00\x00\x10\x01\x0bMillisecond\x1f\x0bj\xe02\x94\t\xdc\xfb\x98EY\x918p\xca\xe2\xad\x01\x05DatesD4,\x06\x00\x08\x80\t\x07\x15\xd59\x00\x00'

```

which to me is vaguely intelligible as some sort of byte representation of the julia datetime type.

My first instinct is that its perhaps corrupted. But every single row follows a similar format, and furthermore, it looks like Julia reads it just fine

```julia
julia> SQLite.query(ssdb, "select datetime from streetsegmentinfraction limit 5")
5×1 DataFrame
│ Row │ datetime │
├─────┼─────────────────────┤
│ 1 │ 2016-01-01T00:00:00 │
│ 2 │ 2016-01-01T00:01:00 │
│ 3 │ 2016-01-01T00:02:00 │
│ 4 │ 2016-01-01T00:02:00 │
│ 5 │ 2016-01-01T00:02:00 │

```

I googled around for what kind of encoding this might be, but didn’t find anything that looked helpful, which may be due to me not knowing what to look for.

If it’s any help, I’m on Julia 1.0, running on a linux machine.

I’d appreciate any leads on this. Cheers!

---

<div class="post-metadata">

### Author: ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)
#### Post date: [October 16, 2018, 3:43pm UTC](https://discourse.julialang.org/t/datetimes-and-sqlite-jl-encoding/16412/2 "2018-10-16T15:43:43Z")

</div>

DateTimes in SQLite.jl use julia’s builtin `serialize` format; for compat with other sqlite clients, you’d probably be best off to call `string` on the values first.

---

<div class="post-metadata">

### Author: ![mosiman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mosiman/32/6959_2.png) [@mosiman](https://discourse.julialang.org/u/mosiman)
#### Post date: [October 17, 2018, 2:53am UTC](https://discourse.julialang.org/t/datetimes-and-sqlite-jl-encoding/16412/3 "2018-10-17T02:53:10Z")

</div>

Thanks, I think that’s the easiest way forward for me. For completeness, are there any alternative ways to go about reading the serealized format in other programs?

---

<div class="post-metadata">

### Author: ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)
#### Post date: [October 17, 2018, 3:26am UTC](https://discourse.julialang.org/t/datetimes-and-sqlite-jl-encoding/16412/4 "2018-10-17T03:26:07Z")

</div>

Not really. I should probably special-case Date/DateTimes in SQLite.jl to store them as text anyway since they’re common and the interop w/ other languages is more important. The use of Julia’s `serialize` should really only be used for custom Julia types that would be more obviously tied to using Julia itself to query.

---

<div class="post-metadata">

### Author: ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)
#### Post date: [October 19, 2018, 12:12pm UTC](https://discourse.julialang.org/t/datetimes-and-sqlite-jl-encoding/16412/5 "2018-10-19T12:12:24Z")

</div>

I opened an issue so I don’t forget: [Convert date/datetimes to text when storing · Issue #160 · JuliaDatabases/SQLite.jl · GitHub](https://github.com/JuliaDatabases/SQLite.jl/issues/160)
