R Converting from datetime to date

14,695

Solution 1

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)

Solution 2

Convert datetime column in date format

df$DATETIME<-as.Date(df$DATETIME)
Share:
14,695
Dario Federici
Author by

Dario Federici

Updated on June 16, 2022

Comments

  • Dario Federici
    Dario Federici about 2 years

    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?