Page 1 of 1

Dateadd does not work under certain conditions

Posted: Wed Mar 30, 2016 6:37 am
by fboralli
Today is 2016-03-30

This expression does not work(returns NA):

Code: Select all

@dateadd(@now,-1,"mm")
I think that is because February does not have the day 30. However, in most languages this sort of expression works.

For instance, in TSQL:

Code: Select all

select dateadd(month,-1,cast(GETDATE() as date)) ---------- 2016-02-29 (1 row(s) affected)

I have already made an workaround, so it is not urgent, but this behavior is erratic, and I would like this fixed.

Dateadd does not work under certain conditions

Posted: Wed Mar 30, 2016 10:22 am
by EViews Gareth
This is not a bug, but is just the way that dates are handled in EViews. 30 February does not exist, so NA is returned.

The behavior is not erratic, it is very well defined.

Re: Dateadd does not work under certain conditions

Posted: Wed Mar 30, 2016 11:44 am
by fboralli
You mean I have to check every time I want to subtract a month from a date?
And by this you don't think it is erratic?

Re: Dateadd does not work under certain conditions

Posted: Wed Mar 30, 2016 11:53 am
by EViews Gareth
Inconvenient, perhaps. But not erratic - the behaviour is not random or ill-defined.

The real issue is that there is no "correct" way to handle this. In a real sense there is no correct answer. 30 February does not exist. In many (perhaps most) applications, the fact that 31 March, 30 March, 29 March and 28 March would all give the same result is not correct.

Since there is no "correct" way, software applications have to choose an answer to give. We decided on the NA result (since literally 30th Feb doesn't exist). Whichever solution your provide, however, it is usually straight forward to work around it to get the alternative.