Not able to Sort date of data Frame

I have a temp data frame which has dates as below. I am trying to sort it with dates, but output is not coming correctly. For example, 20-May-2021 is coming at No4 in place of at top

temp%>%arrange(EXPIRY_DT=as.Date(EXPIRY_DT,"%dd/%mmm/%YYYY"))
EXPIRY_DT
1 27-May-2021
2 24-Jun-2021
3 29-Jul-2021
4 20-May-2021
5 03-Jun-2021
6 10-Jun-2021
7 17-Jun-2021
8 01-Jul-2021
9 08-Jul-2021
10 15-Jul-2021
11 30-Sep-2021
12 30-Dec-2021
13 31-Mar-2022
14 30-Jun-2022
15 29-Dec-2022
16 29-Jun-2023
17 28-Dec-2023
18 27-Jun-2024
19 26-Dec-2024
20 26-Jun-2025
21 24-Dec-2025

This is because your date specification is failing to parse. Run only as.Date(temp$EXPIRY_DT, "%dd/%mmm/%YYYY") to see this. Change dd to d, mmm to B, and YYYY to just Y:

arrange(temp, EXPIRY_DT=as.Date(EXPIRY_DT, "%d-%B-%Y"))

Here's where I found the date format specifications, but I'm sure there are many other places: Date Formats in R | R-bloggers

Thanks. Its working now.

Great! Would you mind going ahead and marking it as a solution? That will let others know a solution was found when they're searching for the same problem!

This topic was automatically closed 7 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.