Matias.10
Matias.10

Reputation: 53

One single number to date and hour format in R

I need help to convert a column wich contains the date in one number like 20160317000043, and put it into format 2016/03/17 00:00:43 (or the date and hour in different columns). I searched a lot, but I couldn't find how to do this: as.date is for string dates, but I have a number, and it is no delimiter between date and hour!

I'm sorry if the question it's not in the proper format. I'm learning how to do it. Thank you.

Upvotes: 1

Views: 606

Answers (1)

Karsten W.
Karsten W.

Reputation: 18420

You could convert the number to character, and run strptime on it:

d <- 20160317000043
strptime(as.character(d), "%Y%m%d%H%M%S")
# [1] "2016-03-17 00:00:43 CET"

Upvotes: 3

Related Questions