Gianluca
Gianluca

Reputation: 6657

Extract week number from POSIXct object

Is there a function in lubridate to extract the week number? I've tried to search for that but couldn't find anything which serves the purpose.

The week() function does something different.

Description

Date-time must be a POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg, timeDate, xts, > its, ti, jul, timeSeries, and fts objects. Weeks is the number of complete seven day periods that have occured between the date and January 1st, plus one. isoweek returns the week as it would appear in the ISO 8601 system, which uses a reoccuring leap week.

Upvotes: 10

Views: 16809

Answers (1)

Prasanna Nandakumar
Prasanna Nandakumar

Reputation: 4335

Use strftime:

dateRange <- c("2008-10-01","2008-12-01") 
x <- as.POSIXlt(dateRange) 
strftime(x,format="%W") 
[1] "39" "48" 

Upvotes: 12

Related Questions