Skip to content

date handling

3 messages · Richard van Wingerden, paul sorenson, JeeBee

#
Hi,

Given a frame with calendar date's:

"2005-07-01", "2005-07-02","2005-07-03","2005-07-04","2005-07-05",etc.

I want to extract the following from these dates:

week number
month number
year number

Any ideas how to accomplish this?

Many thanks.

Regards,
Richard
#
d = as.POSIXlt(c("2005-07-01", "2005-07-02", "2005-07-03", "2005-07-04", 
"2005-07-05"))
d$mon and d$year will get you part way there.

That is assuming your dates are formated yyyy-mm-dd.  strptime() might 
also be useful.
Richard van Wingerden wrote:
#
D = as.POSIXlt(c("2005-07-01", "2005-07-02",
  "2005-07-03", "2005-07-04", "2005-07-05"))
[1] 2005 2005 2005 2005 2005
[1] 7 7 7 7 7
[1] "Friday"   "Saturday" "Sunday"   "Monday"   "Tuesday"

# you better check this one carefully !!!
(Weeknumbers = floor((D$yday+7)/7))


JeeBee
On Mon, 12 Dec 2005 12:59:11 +0100, Richard van Wingerden wrote: