# How to determine a month is within a range?

#### Andrew2009

##### Well Known Member
I have a certain number of winter months that starts from November 16th and end through April 30th

Users will enter 2 values in the processing options as numbers

a month (12 for december, 3 for march for example)
a day (1 thru 31)

I need to determine if it falls within these winter months or not. Year is not important

Do you know how to do that?

Thanks

Something like this should work .. this does not check if the day/month combo itself is valid (there is probably a bsfn out there to validate that) .

VA evt_WinterMonth = "0"
If VA evt_Month is equal to "11" And VA evt_Day is greater than or equal to "16" And VA evt_Day is less than or equal to "30"
VA evt_WinterMonth = "1"
End If
If VA evt_Month is equal to "4" And VA evt_Day is greater than or equal to "1" And VA evt_Day is less than or equal to "30"
VA evt_WinterMonth = "1"
End If
If VA evt_Month is equal to "12" Or VA evt_Month is greater than or equal to "1" And VA evt_Month is less than or equal to "3"
VA evt_WinterMonth = "1"
End If
If VA evt_WinterMonth is equal to "1"
End If

Will the fiscal pattern for the company Regular or can be different as well?
That will change the logic suggested.

Thanks everyone. Fiscal year is the same as Calendar year.

Instead of hard coding "30", is there a bsfn that will return the number of days in a month? For example, let's say I pass in 4 for April then it will return "30" days. If I pass in 7 for July then it will return "31"

Thanks

Create a 4-digit number of your processing options: MMDD (with leading zeros on both month and days)

If MMDD >= 1116 or MMDD <= 0430
wintermonth!
endif

Have you seen this guy?

BSFN - User Date, Format - B0000078
This BSFN can perform in 2 modes.

(2) <> mnMonth DMTM
(2) <> mnDay DMTD
(2) <> mnYear DMTY
(2) <> mnCentury DMT#
(6) <> jdReturnDate DATE01
‘ ‘ / ‘1’ > cProcessingFlag

Pass a blank ‘ ‘ to bring back the date from the bits.

Pass a ‘1’ to bring back the bits from the passed in date.

So bring back the M and D and then just compare the values. I'd start with month first, then if in range, check the day

Create a 4-digit number of your processing options: MMDD (with leading zeros on both month and days)

If MMDD >= 1116 or MMDD <= 0430
wintermonth!
endif

Jeremy - won't this always return false (as 0430 < 1116)? I like your idea, but it should be:

(MMDD >= 1116 and MMDD <= 1231) or (MMMD >= 1 and MMMD <= 0430)

Jeremy - won't this always return false (as 0430 < 1116)? I like your idea, but it should be:

(MMDD >= 1116 and MMDD <= 1231) or (MMMD >= 1 and MMMD <= 0430)

I don't think so if I'm understanding the OP's requirement. Any valid Month/Day combo entered in the processing options should work just fine in my condition without the need for the additional conditions.
Your condition works, too, but I guess I'm saying it is not necessary to condition with the 1231 and the 1.

Hari,

I think you are mistaking the OR for an AND in Jeremy's solution:

If MMDD >= 1116 OR MMDD <= 0430

The MMDD value is always going to be between 0101 and 1231 so if the value is say 1117 then it would be true as one of the conditions (1117 >= 1116) would be true. If the value is 0429 it would be true as one of the conditions (0429 <= 0430) is true. But of it is 0516 neither condition would be true so the result would be false.

Peter, Jeremy: Yep .. you are right .. was not thinking straight!

Last edited:

Replies
0
Views
947
JohnDanter2
Replies
2
Views
2K
FrankCLT
Replies
27
Views
3K
DaveWagoner
Replies
11
Views
3K
JohnBartolucci
Replies
4
Views
3K
jigarmehta