Help - How to Set Date Data Type

hi folk,

i new to R community and just started working with R.

i am kind of stuck with one small problem.

i have Data Set like below:

Id TransName TransDate
1 ABC 22-04-2015
2 XYZ 4/8/2015
3 PQR 18-04-2015
4 XYZ 5/7/2015
5 RST 26-05-2015

basically when i am trying to convert above TransDate with as.Date its not working as per desired.
i am kind of frusted after googling it by many ways and i didnt find any solution.
i want to covert this date in one proper format. all of them should be either 01-01-2020 or 01/01/2020.
appreciate your help.

Thanks.
Devang Tadvi

use the lubridate package

as.Date("22-04-2015")
# [1] "0022-04-20"
 lubridate::dmy("22-04-2015")
#[1] "2015-04-22"
1 Like

R versions 3.3.3 is now 4 years old, which is almost a lifetime when it comes to technology, any chance you would upgrade ?

No need for any other package. Just resolve the format conflicts and specify the date format:

as.Date(gsub("/", "-", TransDate), format = "%d-%m-%Y")

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

thanks but it gave me error: package ‘lubridate ’ is not available (for R version 3.3.3)