Welcome to the community!
I think you're looking for something like this:
data_example <- "16/12/2017"
data_example
#> [1] "16/12/2017"
data_as_date <- as.Date(x = data_example,
format = "%d/%m/%Y")
data_as_date
#> [1] "2017-12-16"
data_displayed_in_desired_format <- format(x = data_as_date,
format = "%Y/%m/%d")
data_displayed_in_desired_format
#> [1] "2017/12/16"
Created on 2019-06-15 by the reprex package (v0.3.0)
Your data (16/12/2017
) is in the format DD/MM/YYYY
, and hence the format "%Y/%m/%d"
that you have used here doesn't work correctly. You should use "%d/%m/%Y"
. You can learn about these formats in the documentation of strptime
.
Hope this helps.
For your future posts, please provide a REPRoducible EXample of your problem. It provides more specifics of your problem, and it helps others to understand what problem you are facing.
If you don't know how to do it, take a look at this thread: