2
I have a dataframe with a date string and another time column:
And I want to concatenate the date with the time to stay in the string format "2016-12-25T08:38:00"
Initially I was trying this way:
datainicial=vpnsessions2[1,3]
View(datainicial)
horainicial=vpnsessions2[1,4]
View(horainicial)
dataehora=paste(datainicial,horainicial,sep="T")
But the result I get is:
17160T31080
After researching I found that the hour part is in seconds, and the date part I’m not sure, but I think it’s in days.
I managed to solve the hour by doing the following:
td <- seconds_to_period(horainicial)
dataehorain=paste(datainicial,sprintf('%02d:%02d:%02d', td@hour, minute(td), second(td)),sep="T")
View(dataehorain)
But the result is still not satisfactory:
17160T08:38:00
The time already appears well but the date does not.
I’ve tried several ways to try to get the date right, but I’m not getting it.
View image with code and values: https://snag.gy/koJca2.jpg
Just a hint: instead of putting a link with an image of the code, it is better to [Edit] the question and add the code to it (as text, not as image). See more details in this answer.
– hkotsubo
A better title for this question is: "how to add a number of days to a date"
– Marcos Banik