[R] getting ISO week

Gustaf Rydevik gustaf.rydevik at gmail.com
Thu Dec 11 18:21:33 CET 2008

On Thu, Dec 11, 2008 at 2:10 PM, Prof Brian Ripley
<ripley at stats.ox.ac.uk> wrote:
> A slightly simpler version is
> format(Sys.Date(), "%V")
> On Thu, 11 Dec 2008, Prof Brian Ripley wrote:
>> strftime(x, "%V")
>> E.g.
>> strftime(as.POSIXlt(Sys.Date()), "%V")
>> is "50", and you might want as.numeric() on it.
>> Note that this is OS-dependent, and AFAIR Windows does not have it.


On Thu, Dec 11, 2008 at 2:15 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> format(d, "%U") and format(d, "%W") give week numbers using
> different conventions.  See ?strptime

Thank you both for your replies!

I'm on windows, so prof Ripleys solution does not work (why is this
Regarding Gabor's solution, neither convention follow the ISO 8601
standard, which is used in Europe (and Sweden in particular). See
http://en.wikipedia.org/wiki/ISO_8601#Week_dates .
So it seems that my function does fill a hole, however small....

I know that for me, working with week numbers, which are used quite
heavily in Sweden, have always been a major frustration.
Would it be possible to implement something similar to my solution in
base, and how should I go about making it fit in to the rest of the
date functions?


Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE

More information about the R-help mailing list