Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 6536 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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?

Posted

Try this in your set field script:

Let(cd = Get(CurrentDate); Date(Month(cd)-1; 1; Year(cd)) & "..." & Date(Month(cd); 0; Year(cd)))

Posted

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?

Posted

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

Posted

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.

This topic is 6536 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.