I have a following datasets
I want to convert these rows in date datatype by using Posixct
right now I am using
as.POSIXct(q3_dos_log$INSERTED_ON , format=c("%d-%mm-%Y"))
but giving wrong output, Kindly solve this.
I have a following datasets
I want to convert these rows in date datatype by using Posixct
right now I am using
as.POSIXct(q3_dos_log$INSERTED_ON , format=c("%d-%mm-%Y"))
but giving wrong output, Kindly solve this.
lubridate
library is your friend, which can parse many types of dates automatically (if it doesn't, you can specify what format the data is in, to help the package figure it out).
library(lubridate)
x = "28-Sep-2017"
as.POSIXct(parse_date_time(x, "dmy"))
There is really no need for lubridate
here in my opinion; just use base R's as.POSIXct
:
as.POSIXct("09-Oct-2017", format = "%d-%b-%Y")
#[1] "2017-10-09 AEDT"
Reformat as "09-10-2017"
string:
format(as.POSIXct("09-Oct-2017", format = "%d-%b-%Y"), format = "%d-%m-%Y")
# [1] "09-10-2017"
We could use anydate
from anytime
to pick up the formats automatically
anytime::anydate("09-Oct-2017")
#[1] "2017-10-09"
All you need is as.Date in Base R and knowledge of the formatting options for dates:
as.Date("07-May-2017", format = "%d-%B-%Y")
See more here: https://www.google.se/amp/s/www.r-bloggers.com/date-formats-in-r/amp/