Reputation: 403
I have the below date format stored as factors as one of the columns in the Data frame:
2017-02-19T21:10:18.664+00:00
2017-03-10T21:40:50.398+00:00
Sample Data:
head(dataset$local_end_datetime)
[1] 2017-02-19T21:10:18.664+00:00 2017-02-19T21:10:38.418+00:00
[3] 2017-03-10T21:40:50.398+00:00 2017-03-11T16:41:43.339+00:00
[5] 2017-03-10T21:43:31.092+00:00 2017-03-10T21:34:36.065+00:00
I need to split the same for date and time. I can find get the date extracted using below:
dataset$Date <- as.Date(dataset$local_end_datetime)
How can I extract the time from above format? I don't know regular expressions.
Upvotes: 1
Views: 316
Reputation: 403
Library Lubridate is quite powerful when it comes to manipulating dates
dataset$datetime <- lubridate::ymd_hms(dataset$local_end_datetime)
dataset$Local_Date <- as.Date(dataset$datetime)
dataset$Local_Time <- format(dataset$datetime,"%H:%M:%S")
Upvotes: 1