I can not keep the format of a date received from a dataframe

2

I have a dataframe with a date column and another time column:

AndIwanttoconcatenatethedatewiththetimetobeinthestringformat"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 searching I found that the time share is in seconds, and the date part is not sure, but I think it's in days.

I was able to sort out the time part 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 fine but the date does not.

I have tried several ways to try to put the date right, but I can not.

View image with code and values: link

    
asked by anonymous 11.05.2018 / 12:55

1 answer

4

You're right. The date is the number of days since the "unix epoch". To get the date in the format you want:

as.Date("1970-01-01", format = "%Y-%m-%d") + 17160
[1] "2016-12-25"
    
11.05.2018 / 15:40