date manipulation crashing when month is feb

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

BT454
Posts: 139
Joined: Wed Aug 02, 2017 6:07 am

date manipulation crashing when month is feb

Postby BT454 » Thu Apr 29, 2021 11:06 am

Hi all,
This piece of code works for any month, except feb (i..e if the @dateadd determines any month other than feb, it will correctly return the requested date string. But for Feb it returns "?". And unfortunately, Feb is the month I need to assign the string to. Any thoughts?
Thanks!
Bob

Code: Select all

close @wf wfcreate(wf=test) m 2016 2016 !dom=@datepart(@dateval(@date),"dd") if !dom > 10 then %enddate = @datestr(@dateadd(@dateval(@date),-2,"mm"),"yyyy") statusline check ok else %enddate = @datestr(@dateadd(@dateval(@date),-3,"mm"),"mm/dd/yyyy") statusline check bad endif show %enddate

BT454
Posts: 139
Joined: Wed Aug 02, 2017 6:07 am

Re: date manipulation crashing when month is feb

Postby BT454 » Thu Apr 29, 2021 11:08 am

Ah... I bet it's because it's the 29th, and feb only has 28 days this year....

BT454
Posts: 139
Joined: Wed Aug 02, 2017 6:07 am

Re: date manipulation crashing when month is feb

Postby BT454 » Thu Apr 29, 2021 11:26 am

Is there a way to code a string that returns the first day of the month instead of the current day? I'm playing around with @datefloor but I can't seem to pass the value to a string or scalar.
Thanks!
Bob

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

Re: date manipulation crashing when month is feb

Postby EViews Gareth » Thu Apr 29, 2021 12:13 pm

Combination of @datestring and @datefloor


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests