Re your Post #18
First-off, that ungainly Iif() statement isn't doing what you may think:
1) It refers to "w", which represents Weekdays (same as "d" for Days) when it's plain it's after Weeks (e.g. >52). For that, you need to use "ww"
2) Doesn't take into account that the DateDiff() function merely subtracts one month from another without consideration if there's truly a month's difference. Works the same on Years and Weeks. For example, today is 25 Mar 09. Datediff("m", date(), #4/1/09#) will return 1, when in fact a full month won't pass until 4/25/09.
I've cleaned-up the code, replacing "w" with "ww". Problem being, it's not always going to return the correct answer (see 2), above). You can feed a variable to it representing a date, rather than always hard-coding the date.
Here it is. Copy the below to the immediate window, then press <enter> after each line.
x = #4/1/55#
It'll return 1, which is incorrect.
Gotta ask -- What's wrong with the code provided in Post #12?
Seems to me that it's a little easier to type:
? NumMonths(#4/1/55#) <enter>
...than contend with that monster Iif() statement.
Just my opinion. -- Bob
First-off, that ungainly Iif() statement isn't doing what you may think:
1) It refers to "w", which represents Weekdays (same as "d" for Days) when it's plain it's after Weeks (e.g. >52). For that, you need to use "ww"
2) Doesn't take into account that the DateDiff() function merely subtracts one month from another without consideration if there's truly a month's difference. Works the same on Years and Weeks. For example, today is 25 Mar 09. Datediff("m", date(), #4/1/09#) will return 1, when in fact a full month won't pass until 4/25/09.
I've cleaned-up the code, replacing "w" with "ww". Problem being, it's not always going to return the correct answer (see 2), above). You can feed a variable to it representing a date, rather than always hard-coding the date.
Here it is. Copy the below to the immediate window, then press <enter> after each line.
x = #4/1/55#
Code:
? Iif(DateDiff("ww",Date(),DateAdd("yyyy",(DateDiff("yyyy",x,Date())+1),x))>52, DateDiff("ww",Date(),DateAdd("yyyy",(DateDiff("yyyy",x,Date())+1),x))-52, DateDiff("ww",Date(),DateAdd("yyyy",(DateDiff("yyyy",x,Date())+1),x)))
It'll return 1, which is incorrect.
Gotta ask -- What's wrong with the code provided in Post #12?
Seems to me that it's a little easier to type:
? NumMonths(#4/1/55#) <enter>
...than contend with that monster Iif() statement.
Just my opinion. -- Bob