Reputation: 1036
Is there a way to do something like this (this is in R)
df$dataCol <- as.Date(df$dataCol, format="%Y%m%d")
where the dataCol is of the format "20151009".
Upvotes: 5
Views: 895
Reputation: 1036
Is this the best way to do the first part of my question
using Dates
dateReported = map((x) -> string(x), df[:DateReported])
df[:DateOccurred] = map((x) -> if match(r"^((19|20)\d\d)(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])", x)!=nothing Date(x, DateFormat("yyyymmdd")) end, dateOccurred)
Upvotes: 0
Reputation: 32401
There is a Date
constructor with an argument for the format,
but the syntax is slightly different.
using Dates
Date( "20141123", DateFormat("yyyymmdd") )
Upvotes: 3