Atharva
Atharva

Reputation: 6969

How to access individual attribute like hour, minute from POSIXlt date object in R?

sampleDate <- "08/15/2015 00:00"
sampleDateObject <- strptime(sampleDate, "%m/%d/%Y %H:%M")

Now how to get day, year, month etc. from this sampleDateObject?

Upvotes: 1

Views: 48

Answers (2)

Stewart Macdonald
Stewart Macdonald

Reputation: 2142

sampleDateObject[['year']]

will return 115, which is the number of years after 1900. Details available with ?POSIXlt.

Upvotes: 1

Atharva
Atharva

Reputation: 6969

OK, I found the answer.

sampleDateObject$mon # to access month from 0-11

To access other attributes, check this page https://stat.ethz.ch/R-manual/R-devel/library/base/html/DateTimeClasses.html

Upvotes: 0

Related Questions