January 3, 200719 yr So, I have a script that finds all of the invoices for last month that meet certain criteria. To make the script work every month with no user interaction, in my script, I have a step that does a set field of: Month(Get(CurrentDate)) -1 For example, if I do that find in September, I would get 8/*/06 in my date field. This works for every month but January. When I do that I get a 500 error - it seems to treat it as an invalid date. I would have thought that this would work. Is this a bug, or is this behavior by design? any thoughts on the easiest way around this either way?
January 3, 200719 yr Try this in your set field script: Let(cd = Get(CurrentDate); Date(Month(cd)-1; 1; Year(cd)) & "..." & Date(Month(cd); 0; Year(cd)))
January 3, 200719 yr Author Cool, thanks for the tip, I will actually use that. I guess I am still curious if there is a reason that the: month(get(currentdate)) - 1 errors though, if that works. Especially if in you solution, it seems like you are doing the same thing.. just a little more drawn out. Am I missing something with the date functions?
January 3, 200719 yr If you have a month of 1 and you subtract 1, what does that come out to be? 1-1 = 0. There is no month 0. The proper way to get the previous month would be to Date(Month(Get(CurrentDate))-1; Day (Get(CurrentDate)); Year(Get(CurrentDate)) As for more information on how dates work, rather than me typing it all out, this post may provide some light. Date Discussion
January 3, 200719 yr Another option would be to use: Mod ( Month ( Get ( CurrentDate ) ) - 2 ; 12 ) + 1 instead of: Month ( Get ( Currentdate ) ) - 1 This would fold back to December when CurrentDate is in January, just like the Date() function does. However, John's suggestion is better practice, since it does not depend on file/system date settings.
Create an account or sign in to comment