I have a following dataframe in R
ID Date1 Date2
1 21-03-16 8:36 22-03-16 12:36
1 23-03-16 9:36 24-03-16 01:36
1 22-03-16 10:36 25-03-16 11:46
1 23-03-16 11:36 28-03-16 10:16
My desired dataframe is
ID Date1 Date1_time Date2 Date2_time
1 2016-03-21 08:36:00 2016-03-22 12:36:00
1 2016-03-23 09:36:00 2016-03-24 01:36:00
1 2016-03-22 10:36:00 2016-03-25 11:46:00
1 2016-03-23 11:36:00 2016-03-28 10:16:00
I can do this individually using strptime
like following
df$Date1 <- strptime(df$Date1, format='%d-%m-%y %H:%M')
df$Date1_time <- strftime(df$Date1 ,format="%H:%M:%S")
df$Date1 <- strptime(df$Date1, format='%Y-%m-%d')
But,I have many date columns to convert like above. How can I write function in R which will do this.