Sam
>No. I have looked at both tables and both curdue and daterecv column have dates in it. Thanks, Sam
Good scientific method requires that you investigate by using a pair of dates for which your function is returning different results. Please show us such a pair.
I must also point out that code that COUNTS the days by looping gets slower as the number of days between the two dates increases.
This performance problem will be magnified by calling the UDF in an SQL command, as it will operate on every row in the table. I know some people say don't bother optimizing until later, but I say don't add slow parts in the first place.
The UDF is a component and it is good practice for a component to hide complexity from the rest of the application's components at runtime. So it's not important if the UDF is easy to code, just that it works and is fast and reliable.
In the interest of modern FoxPro code, look at this version of your UDF:
You should use LPARAMETERS not just PARAMETERS. t represents a parameTer. l represents local. Use Vartype() instead of type whenever possible. Declare variables as LOCAL. Such a function should generate an error instead of returning 0 when bad dates are passed to it. That may be part of the reason you're having a problem.
LPARAMETERS m.td1,m.td2
if (vartype(m.td1)="D" and vartype(m.td2)="D")
LOCAL m.lnwd, m.lnD
m.lnwd=0
for m.lnD=0 to ABS(m.td2-m.td1)
if between(DOW(m.td1+m.lnD,1),2,6)
m.lnwd=m.lnwd+1
endif
endfor
return m.lnwd
else
return 0
endif
See also:
http://fox.wikis.com/wc.dll?Wiki~Weekdays~VFP