Skip to content
Prev 306503 / 398506 Next

Start and End day of a month

On Thu, Sep 27, 2012 at 8:21 AM, Rantony <antony.akkara at ge.com> wrote:
This converts the input to a "yearmon" class object which represents
the date as just a year and month.  We then convert it back to "Date"
class using the frac argument to indicate whether the first or last of
the month is to be used.  Finally we paste the time to it which also
converts it to character.

library(zoo)

d <- "2012-09-27"
ym <- as.yearmon(d)

StartDt <- paste(as.Date(ym, frac = 0), "00:00:01")
EndDt <- paste(as.Date(ym, frac = 1), "23:59:59")