Re: [R] Does POSIXlt extract date components properly?

From: Luke Miller <millerlp_at_gmail.com>
Date: Tue, 01 Mar 2011 12:17:43 -0500

Month counts from 0 in POSIXlt objects, so that April is month 3 in your example, January being month 0.

Year counts from 1900 in POSIXlt objects, so that 2005 should return as 105 in your example.

All of the other fields in POSIXlt should return values that you might expect them to a priori. Keep an eye on daylight savings time adjustments if they apply in your time zone.

On Tue, Mar 1, 2011 at 12:01 PM, Seth W Bigelow <sbigelow_at_fs.fed.us> wrote:

> I would like to use POSIX classes to store dates and extract components of
> dates. Following the example in Spector ("Data Manipulation in R"), I
> create a date
>
> > mydate = as. POSIXlt('2005-4-19 7:01:00')
>
> I then successfully extract the day with the command
>
> > mydate$day
> [1] 19
>
> But when I try to extract the month
>
> > mydate$mon
> [1] 3
>
> it returns the wrong month. And mydate$year is off by about 2,000 years.
> Am I doing something wrong?
>
> Dr. Seth W. Bigelow
> Biologist, USDA-FS Pacific Southwest Research Station
> 1731 Research Park Drive, Davis California
> sbigelow_at_fs.fed.us / ph. 530 759 1718
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
___________________________
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 01 Mar 2011 - 17:53:02 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Mar 2011 - 18:10:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive