# Csv dateformat

**URL:** <https://discourse.julialang.org/t/csv-dateformat/47480>\
**Category:** New to Julia\
**Tags:** csv\
**Created:** [September 29, 2020, 12:20pm UTC](https://discourse.julialang.org/t/csv-dateformat/47480 "2020-09-29T12:20:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmetivie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmetivie/32/6926_2.png) [@dmetivie](https://discourse.julialang.org/u/dmetivie)\
**Post date:** [September 29, 2020, 12:20pm UTC](https://discourse.julialang.org/t/csv-dateformat/47480/1 "2020-09-29T12:20:31Z")

</div>

Hello,  
I want to import data with a structure like that

```julia
code,date
0,20190101
1,20190102

```

If I do

```julia
t = CSV.read("file.txt"; dateformat="yyyymmdd")
2×2 DataFrame
│ Row │ code │ date │
│ │ Int64 │ Int64 │
├─────┼───────┼──────────┤
│ 1 │ 0 │ 20190101 │
│ 2 │ 1 │ 20190102 │

```

it does not recognize the date structure treating the date as a Int.  
However, for

```julia
code,date
0,2019-01-01
1,2019-01-02

```

it works when I do

```julia
t = CSV.read("file.txt"; dateformat="yyyy-mm-dd")
2×2 DataFrame
│ Row │ code │ date │
│ │ Int64 │ Date │
├─────┼───────┼────────────┤
│ 1 │ 0 │ 2019-01-01 │
│ 2 │ 1 │ 2019-01-02 │

```

Similarly, it works with /.

I thought that CSV could recognize the dateformat yyyymmdd if specified like I do. Are there any reasons I am not seeing on why it does not work ?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 29, 2020, 1:53pm UTC](https://discourse.julialang.org/t/csv-dateformat/47480/2 "2020-09-29T13:53:48Z")

</div>

I suppose that `20190101` etc are recognized as `Int`s, so maybe you should try manually specifying the column type as `Date`. See the docs at

[https://juliadata.github.io/CSV.jl/stable/#CSV.File](https://juliadata.github.io/CSV.jl/stable/#CSV.File)

---

<div class="post-metadata">

**Author:** ![dmetivie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmetivie/32/6926_2.png) [@dmetivie](https://discourse.julialang.org/u/dmetivie)\
**Post date:** [September 30, 2020, 8:53am UTC](https://discourse.julialang.org/t/csv-dateformat/47480/3 "2020-09-30T08:53:52Z")

</div>

Thanks ! It works when combining dateformat and types.

```julia
t = CSV.read("file.txt"; dateformat = "yyyymmdd", types = Dict(:date => Date) )
2×2 DataFrame
│ Row │ code │ date │
│ │ Int64 │ Date │
├─────┼───────┼────────────┤
│ 1 │ 0 │ 2019-01-01 │
│ 2 │ 1 │ 2019-01-02 │

```
