Search code examples
rdatelubridate

how to express the 15th day of the current month in lubridate


I would like to create an if-else statement, where it prints today's date if the current date is after the 15th of every month, or else it should print last month's date if the current date is before the 15th of every month. I'm having trouble figuring out how to express the 15th of the current month in the right hand side of my test expression, any ideas on how to do this?

library(lubridate)
ifelse(Sys.Date() >  15TH_OF_THE_MONTH, Sys.Date(), Sys.Date() - months(1))

Solution

  • library(lubridate)
    ifelse(day(Sys.Date()) > 15, TRUE, FALSE)
    [1] TRUE