Dateadd does not work under certain conditions

For notifying us of what you believe are bugs or errors in EViews.
Please ensure your copy of EViews is up-to-date before posting.

Moderators: EViews Gareth, EViews Moderator

fboralli
Posts: 20
Joined: Tue Feb 10, 2015 1:52 pm

Dateadd does not work under certain conditions

Postby fboralli » Wed Mar 30, 2016 6:37 am

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13312
Joined: Tue Sep 16, 2008 5:38 pm

Dateadd does not work under certain conditions

Postby EViews Gareth » Wed Mar 30, 2016 10:22 am

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.
Follow us on Twitter @IHSEViews

fboralli
Posts: 20
Joined: Tue Feb 10, 2015 1:52 pm

Re: Dateadd does not work under certain conditions

Postby fboralli » Wed Mar 30, 2016 11:44 am

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?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13312
Joined: Tue Sep 16, 2008 5:38 pm

Re: Dateadd does not work under certain conditions

Postby EViews Gareth » Wed Mar 30, 2016 11:53 am

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.
Follow us on Twitter @IHSEViews


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 12 guests