Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Converting from datetime to date

I have to do a difference between dates and return the number of days. the format of the dates is as follows:

12/9/2011 12:00:00 AM

Does anyone know how to perform the difference without using lubridate?

like image 352
Dario Federici Avatar asked Dec 25 '22 04:12

Dario Federici


2 Answers

We can use asPOSIXct to convert to DateTime

v1 <- as.POSIXct("12/9/2011 12:00:00 AM", format = "%d/%m/%Y %I:%M:%S %p")

If we need only Date

as.Date(v1)
like image 108
akrun Avatar answered Jan 08 '23 17:01

akrun


Convert datetime column in date format

df$DATETIME<-as.Date(df$DATETIME)
like image 40
Rupesh Kumar Avatar answered Jan 08 '23 17:01

Rupesh Kumar