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

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

I have tried

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

and I get the Error

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!

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].

1 Like

You need to provide the format for your date:

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:

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

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

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

Any idea why that would be the case?

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