10-17-2004, 08:49 PM

These are formulas I came up with. I'll try to explain them.

ok when you test an equation, QB returns 0 (false) or -1 (true).

even numbered months before august (month#8) and odd numbered months after July (month#7) have 30 days (except feb, but that's covered in line 2)

So, line 1 is an equation that starts with 31 days and adds the validity of the above statement. If it's true, it subtracts 1, leaving 30 days.

I'll break it apart:

now, we multiply the first two and the second two together:

so if either one of these is true, 31 gets added to -1 and 0 for a result of 30

otherwise, 31 gets added to 0 and 0 for a result of 31

since both products can't be -1, you never end up with 31+ -1 + -1 = 29.

This line does pretty much the same thing, only it starts with 28 as the default value and adds 1 if:

1. the year is evenly divisible by 4, unless the year is evenly divisible by 100 and not evenly divisible by 400.

I hope this clears it up!

*peace*

Meg.

edit: another alternative to line #1 is:

so using your bit of code (which i like!) it would be this:

ok when you test an equation, QB returns 0 (false) or -1 (true).

even numbered months before august (month#8) and odd numbered months after July (month#7) have 30 days (except feb, but that's covered in line 2)

So, line 1 is an equation that starts with 31 days and adds the validity of the above statement. If it's true, it subtracts 1, leaving 30 days.

Code:

`DInM% = 31 + (m% MOD 2) * (m% > 7) + (m% MOD 2 XOR 1) * (m% < 8)`

I'll break it apart:

Code:

`31 default value`

m% MOD 2 returns 0 if date is even, 1 if date is odd

m% > 7 returns -1 if date is > 7, 0 if date < 8

m% MOD 2 XOR 1 returns 0 if date is odd, 1 if date is even

m% < 8 returns -1 if date is < 8, 0 if date > 7

now, we multiply the first two and the second two together:

Code:

`(m% MOD 2) * (m% > 7) returns -1 if date is odd and > 7`

(m% MOD 2 XOR 1) * (m% < 8) returns -1 if date is even and < 8

so if either one of these is true, 31 gets added to -1 and 0 for a result of 30

otherwise, 31 gets added to 0 and 0 for a result of 31

since both products can't be -1, you never end up with 31+ -1 + -1 = 29.

Code:

`IF m% = 2 THEN DInM% = 28 - ((y% MOD 4 = 0) + (y% MOD 100 = 0) * NOT (y% MOD 400 = 0))`

This line does pretty much the same thing, only it starts with 28 as the default value and adds 1 if:

1. the year is evenly divisible by 4, unless the year is evenly divisible by 100 and not evenly divisible by 400.

Code:

`28 default value`

y% MOD 4 = 0 returns -1 if year is divisible by 4, otherwise 0

y% MOD 100 = 0 returns -1 if year is divisible by 100, otherwise 0

y% MOD 400 = 0 returns -1 if year is divisible by 400, otherwise 0

I hope this clears it up!

*peace*

Meg.

edit: another alternative to line #1 is:

Code:

`DinM% = VAL(MID$("312831303130313130313031", m% * 2 - 1, 2))`

so using your bit of code (which i like!) it would be this:

Code:

`DinM% = VAL(MID$("312831303130313130313031", m% * 2 - 1, 2))`

IF DinM% = 2 then DinM% = 28 - ((m% MOD 4 = 0 AND m% MOD 100 <> 0) OR (m% MOD 400 = 0))