I have a year list (format date) and I would to transform this year into a %Y%m%d %H:%M:%S
format and the month must be 01 and day must be 01 as in the example below :
1800
transformed in 1800/01/01 00:00:00
Anybody as a solution ?
I have a year list (format date) and I would to transform this year into a %Y%m%d %H:%M:%S
format and the month must be 01 and day must be 01 as in the example below :
1800
transformed in 1800/01/01 00:00:00
Anybody as a solution ?
Try zoo library:
library(zoo)
> (date <- as.POSIXct(as.yearmon(2010)))
[1] "2010-01-01 GMT"
> format(date, "%Y/%m/%d %H:%M:%S")
[1] "2010/01/01 00:00:00"
EDIT: @user3370470 Please explain yourself. The below confirm what I've been saying so far.
> format(as.POSIXct(as.yearmon(1800)), "%Y/%m/%d %H:%M:%S")
[1] "1800/01/01 00:00:00"
> format(as.yearmon(1800), "%Y/%m/%d %H:%M:%S")
[1] "1800/01/01 00:00:00"
The result of as.POSIXct(as.yearmon(1800)
is a datetime object, class POSIXct
.
I don't know of a date
format - there's a Date
class, do you mean that. If the only info you have is the year, then why not sprintf("%s/01/01 00:00:00", charYear)
where charYear is a vector of string representations of the year.