Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)
Let's say for instance I am having a very huge amount of dataset with millions of columns. One of the column has Dates such as "3/28/2020" (mm/dd/YYYY) format.

For my analysis, I need a format (dd/mm/YYYY)

How can I do that?

2 Answers

0 votes
by (107k points)

In R programming, you can easily convert to standard date class and then use format to get data in desired format.

format(as.Date('3/28/2020', '%m/%d/%Y'), '%d/%m/%Y')

#[1] "28/03/2020"

0 votes
by (3.1k points)

To Convert the date from mm/dd/YYYY to dd/mm/YYYY in R. 

First, start with your date in the form of mm/dd/YYYY 

Then take the character vector and convert it to Date by using as.Date 

Third, convert the Date to a character string by applying format on the Date. 

Create a character vector filled with dates: 

dates_mm_dd <- c("12/25/2024", "01/01/2024", "07/04/2024") 

Convert to Date, format to dd/mm/YYYY: 

dates_dd_mm <- format(as.Date(dates_mm_dd, format = "%m/%d/%Y"), format = "%d/%m/%Y") 

Print the converted date 

print(dates_dd_mm) 

The code above converts dates to proper format and prints. 

Related questions

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...