Getting previous month start date and end date from current date in R

后端 未结 6 1578
心在旅途
心在旅途 2020-12-29 03:55

Is there any easy way for getting start date and end date of previous month from the current date in R?

I have only the current date. From it, i want to get the prev

6条回答
  •  误落风尘
    2020-12-29 04:32

    Using lubridate it's a piece of cake:

    library(lubridate)
    floor_date(Sys.Date() - months(1), "month")
    

    There is a plenty of good libraries in R. Seems like everything you need is already created.

    UPDATED version:

    library(lubridate)
    floor_date(as.Date("2011-03-29"), "month") - months(1)
    

    This one is corrected to work well with the 29th of march.

提交回复
热议问题