Page 1 of 1

date manipulation crashing when month is feb

Posted: Thu Apr 29, 2021 11:06 am
by BT454
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

Re: date manipulation crashing when month is feb

Posted: Thu Apr 29, 2021 11:08 am
by BT454
Ah... I bet it's because it's the 29th, and feb only has 28 days this year....

Re: date manipulation crashing when month is feb

Posted: Thu Apr 29, 2021 11:26 am
by BT454
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

Re: date manipulation crashing when month is feb

Posted: Thu Apr 29, 2021 12:13 pm
by EViews Gareth
Combination of @datestring and @datefloor