Change day of the month in a Date to first day (01)

前端 未结 5 836
别那么骄傲
别那么骄傲 2020-11-30 11:10

I want to set the day of month in a Date to start date of current month (01). Now I use the following:

currentDate <- Sys.Date()         


        
5条回答
  •  無奈伤痛
    2020-11-30 11:49

    Using lubridate (also work with sec, min, hour, mon, year etc.)

    library(lubridate)
    
    dt <- Sys.Date()
    day(dt) <- 01
    
    dt
    # [1] "2018-01-01"
    

提交回复
热议问题