>>Hi everybody,
>>
>>I have strange problem. In SQL Server we have these two datetime values:
>>
>>2014-03-04 09:30:00.000 2014-03-04 10:00:00.000
>>
>>In VFP I have the following script
>>
>>(end_time - start_time)/3600
>>
>>and compare it with .5
>>
>>If it's less than .5 it should be true and otherwise it should be false.
>>
>>So, as we see here, the duration is exactly half an hour and I should get false. But I am getting true and I am not sure why and what may be wrong.
>
>1. Show your actual code, not pseudocode. In the past you've wasted my time and that of others by going off on a wild goose chase
>
>2. How are you getting the SQL Server values into VFP? Are you sure the values you're getting are what you expect i.e. you've debugged/traced it?
>>In VFP I have the following script
>>
>>(end_time - start_time)/3600
>>
>>and compare it with .5
>>
>>If it's less than .5 it should be true and otherwise it should be false.
>>
>>So, as we see here, the duration is exactly half an hour and I should get false. But I am getting true and I am not sure why and what may be wrong.
>
>1. Show your actual code, not pseudocode. In the past you've wasted my time and that of others by going off on a wild goose chase
>
>2. How are you getting the SQL Server values into VFP? Are you sure the values you're getting are what you expect i.e. you've debugged/traced it?
This is exactly the code what I showed. We get values back from SQL Server using SQLEXEC function.
I just updated script to use ROUND and I got the desired result.
Basically, this is a problem on the client. We have Payroll Incentives where we keep scripts to calculate incentives in the database. The exact script is the following in the code
text to lcScript textmerge noshow pretext 2
SELECT csrPayroll
IF (csrPayroll.end_time-csrPayroll.start_time)/3600 <<pcLBound>> <<pcLowVal>> <<IIF(NOT EMPTY(pcUBound), " AND (csrPayroll.end_time-csrPayroll.start_time)/3600 " + m.pcUBound + " " + m.pcHiVal, "")>>
lcReturn = '<STATUS>.T.</STATUS>' + ;
'<MSG>Satisfies Event Duration - Incentive Success</MSG>'
ELSE
lcReturn = '<STATUS>.F.</STATUS>' + ;
'<MSG>Lesson Duration does not satisfy criteria - Incentive Failed</MSG>'
ENDIF
RETURN lcReturn
endtext
I asked my colleague tester to try to reproduce this problem locally. For that client I already found that incentive was evaluated to true when I have duration exactly half an hour but the expression set to be less than .5
SET DECIMALS is set to 2 (default value) in that application, so the problem is not clear. (The SET DECIMALS is not set in the code, so it uses the default VFP setting)
If it's not broken, fix it until it is.
My Blog