Benjamin Williams <ben <at> bwmcct.com> writes: > I am trying to get fields showing the last day of each month for a monthly > closing project. In order to find the last day of the previous month, I > subtract the number of days from the current month. For all months my code > works; however, for October, my code doesn't work...it returns > 2010-09-*29* instead > of 2010-09-*30*. > > format(strptime("2010-10-31", > "%Y-%m-%d")-(as.numeric(format(as.Date("2010-10-31"),"%d"))*24*3600), "%Y-%m-%d")
Very timely question. This is a daylight savings time issue; subtracting 24 hours gives a different answer when there are only 23 hours in a particular day ("spring forward, fall back"). Search the R-help archives for the last week or so for a similar issue. (Hint: try subtracting days from dates rather than converting to seconds first.) Ben Bolker ______________________________________________ R-help@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.