Date & Time splitting and conversion

You can do something like this

library(dplyr)

sample_df <- data.frame(
    time_stamp = c("4/12/2016 7:21:00 AM")
)

sample_df %>% 
    mutate(time_stamp = mdy_hms(time_stamp),
           date = as.Date(time_stamp),
           time = strftime(time_stamp, format="%H:%M:%S", tz = "UTC"))
#>            time_stamp       date     time
#> 1 2016-04-12 07:21:00 2016-04-12 07:21:00

Created on 2022-11-11 with reprex v2.0.2

Note: Next time please provide a proper REPRoducible EXample (reprex) illustrating your issue.

1 Like