# Alter Date List in dd/mm/yyyy format to yyyy format

**URL:** <https://discourse.julialang.org/t/alter-date-list-in-dd-mm-yyyy-format-to-yyyy-format/45031>\
**Category:** General Usage\
**Created:** [August 16, 2020, 9:38am UTC](https://discourse.julialang.org/t/alter-date-list-in-dd-mm-yyyy-format-to-yyyy-format/45031 "2020-08-16T09:38:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![torieowers](https://avatars.discourse-cdn.com/v4/letter/t/6a8cbe/32.png) [@torieowers](https://discourse.julialang.org/u/torieowers)\
**Post date:** [August 16, 2020, 9:38am UTC](https://discourse.julialang.org/t/alter-date-list-in-dd-mm-yyyy-format-to-yyyy-format/45031/1 "2020-08-16T09:38:05Z")

</div>

Hi there! Could anyone help me alter a column of data (49019-element Array{String,1}🙂 to drop the dd/mm and just leave the year?

I have tried

```julia
working_df[!, :DATE] |> string |> Date

```

and I get the Error

```julia
ArgumentError: Unable to parse date time. Expected directive DatePart(yyyy) at char 1

```

Just wondering if anyone has any tips on how to get just the year. Thanks!

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [August 16, 2020, 11:18am UTC](https://discourse.julialang.org/t/alter-date-list-in-dd-mm-yyyy-format-to-yyyy-format/45031/2 "2020-08-16T11:18:56Z")

</div>

If they are already dates (before you call `string`), you can just call `year` on them (and then convert to a string if you want). Alternatively, if they are strings, try providing a `dateformat` to the `Date` constructor to get them to parse correctly. If they are all strings with the same length (e.g. 6 characters for the “dd/mm/”) you could even do `s[7:end]`.

---

<div class="post-metadata">

**Author:** ![anon37204545](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon37204545](https://discourse.julialang.org/u/anon37204545)\
**Post date:** [August 16, 2020, 12:55pm UTC](https://discourse.julialang.org/t/alter-date-list-in-dd-mm-yyyy-format-to-yyyy-format/45031/3 "2020-08-16T12:55:59Z")

</div>

You need to provide the format for your date:

```julia
working_df[!, :DATE] |> string |> x -> Date(x, "dd/mm/yyyy")

```

(as the date parser tell `dd/mm` from `mm/dd` unless it is clearly specified)

And if you want the year, just use `year`:

```julia
working_df[!, :DATE] |> string |> x -> Date(x, "dd/mm/yyyy") |> year

```

---

<div class="post-metadata">

**Author:** ![torieowers](https://avatars.discourse-cdn.com/v4/letter/t/6a8cbe/32.png) [@torieowers](https://discourse.julialang.org/u/torieowers)\
**Post date:** [August 16, 2020, 10:22pm UTC](https://discourse.julialang.org/t/alter-date-list-in-dd-mm-yyyy-format-to-yyyy-format/45031/4 "2020-08-16T22:22:06Z")

</div>

This makes send and looks so close, but when I run this I am getting the error:

```julia
ArgumentError: Unable to parse date time. Expected directive DatePart(dd) at char 1

```

Any idea why that would be the case?

---

<div class="post-metadata">

**Author:** ![anon37204545](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon37204545](https://discourse.julialang.org/u/anon37204545)\
**Post date:** [August 16, 2020, 10:24pm UTC](https://discourse.julialang.org/t/alter-date-list-in-dd-mm-yyyy-format-to-yyyy-format/45031/5 "2020-08-16T22:24:32Z")

</div>

Can you paste a few examples of `working_df[!, :DATE] |> string` results? Seems like the string is malformed.
