dimanche 22 décembre 2019

If else condition works with days?

I required date as mentioned below in if condition.

if day('2019-12-23') <=15 then '2019-11-16' else '2019-12-01'.

I have tried writing codes in R, but output is not correct.

Codes

ifelse(day(Sys.Date()) <=15,
  (ymd(Sys.Date()-day(Sys.Date()-1)) %m-% months(1))+15,
  ymd(Sys.Date()-day(Sys.Date()-1)))

Output

18231

Required Output

2019-12-01

Please help me with the solution.

Aucun commentaire:

Enregistrer un commentaire