Convert chr to date column rstudio

I am not able to convert column Date from :08.06.2023 to 08/06/2023 (Date format ).

Date

08.06.2023
08.06.2023
08.06.2023
08.06.2023
08.06.2023
08.06.2023

You can use the as.Date() function, to convert a given String to date format. Since your example is not a usual date format in R, you have to use the appropriate format within the as.Date() function:

as.Date("08.06.2023", "%d.%m.%Y")

You can convert the text to a Date value using either the as.Date() function or the dmy() function from the lubridate package. These will display the date in the unambiguous YYYY-MM-DD format. If you need to display the date as 08/06/2023 for a presentation or report, that can be done with the format() function but the result will be characters instead of a numeric date.
I have assume your original date is DD.MM.YYYY. If it is MM.DD.YYYY, use the mdy() function from lubridate or swap the %d and %m labels in as.Date().

as.Date("08.06.2023", format = "%d.%m.%Y")
[1] "2023-06-08"
library(lubridate)
dmy("08.06.2023")
[1] "2023-06-08"

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.