On Thu, Sep 27, 2012 at 8:21 AM, Rantony <antony.akkara at ge.com>
wrote:> Hi,
>
> Can anyone please help to get "StartDay" and "End-day of a
particular month"
> with time ?
>
> For eg:- Input wil be "2012-09-27"
>
> i need to get output as given below
>
> StartDt <- "2012-09-01 00:00:01"
> EndDt <- "2012-09-30 23:59:59"
>
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")
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com