How to compare datetime in r?

As I said you have to use dates instead of characters, see this example

library(dplyr)

mydata<- read.table(text="ID Lastupdate
A '2020-04-29 08:02:00'
B '2020-05-20 09:04:12'
C '2020-05-18 10:23:14'
D '2020-05-06 12:00:45'
E '2020-05-10 13:21:45' ", header=T)

mydata %>% 
    mutate(Lastupdate = as.POSIXct(Lastupdate),
           updatecondition = ifelse(Lastupdate > as.POSIXct("2020-05-10 08:00:00"), 'Yes', 'No'))
#>   ID          Lastupdate updatecondition
#> 1  A 2020-04-29 08:02:00              No
#> 2  B 2020-05-20 09:04:12             Yes
#> 3  C 2020-05-18 10:23:14             Yes
#> 4  D 2020-05-06 12:00:45              No
#> 5  E 2020-05-10 13:21:45             Yes

Created on 2020-05-29 by the reprex package (v0.3.0)

1 Like