dateAdd "years" with Feb. 29 in leap year produces wrong date

Wappler Version : 2.1.5
Operating System : Mac / PHP

Expected behavior

What do you think should happen?

The following should produce: “2019-02-28T00:00:00”

{{'2020-02-29'.dateAdd("years", -1)}}

Similarly, when using +1, it should produce: “2021-02-28T00:00:00”

Actual behavior

What actually happens?

With -1 it produces: “2019-03-01T00:00:00”
With +1 it produces: “2021-03-01T00:00:00”

How to reproduce

On server connect, PHP it just breaks on leap year Feb. 29. :slight_smile:

Not sure if it impacts other areas.

Interesting one this. In fact I don’t know what other computing systems do when faced with this calculation. I don’t know the answer and these are only my thoughts. Is my thought process right?

Personally, I think @mebeingken you are wrong when you say the expected results should be as follows…

Why do I say that? Quite simply these dates do not exist. You can’t make up a date that does not or will not exist.

Therefore in my mind,
should -1 produce “2019-03-01T00:00:00” or “2019-02-28T00:00:00”
should +1 produce “2021-03-01T00:00:00” or “2021-02-28T00:00:00” ?

I would be interested to see what others have to say.


Yes…you are absolutely correct!

Modifying my post now.

I think for the intent of adding a year, it should be the last day of Feb., which would match every other month end.

1 Like

I’m inclined to agree with you (on your modified post :wink: )

I think if you use days instead of year you would get the result you wish for. Try using Days and -/+ 365 and see if that gives you the result you wish for.

Thanks Brad. My use case is a very unlikely scenario, so I’m actually not too worried about it – just reporting what I think is a bug. And actually, I think -/+ 365 should always give you exactly that because it is more precise. Years however, seems better suited to the intent.

1 Like