I am moving our disucssions to this thread to keep them at one main place.
You said:
(ownd:numera)->dataultmov is 28/04/15
dDataM is 28/04/15
if (ownd:numera)->dataultmov > dDataM
msginfo("Data do ult doc "+dtoc((ownd:numera)->dataultmov)+CRLF+;
"Data deste doc "+dtoc(dDataM) )
endif
The code inside the IF should never be executed but it is and the msginfo shows both with the same date 28.04.15.
What might be the reason?
First recommended caution is to keep always Century on.
Most date fields in various SQL servers store acutally date-time values, not pure truncated date values. Please keep in mind that I said "most" not "all".
If for some reasons, the value stored in the field is 28/04/2015 00:00:00.001 then this field value is greater than pure date 28/04/2015. Years back I struggled till I found that xHarbour was adding one extra milli second. ( I do not know if this is ok now)
We need to be extra-cautious while dealing with dates in sql databases. For the purpose of ADORDD, please return truncated date ( with valtype 'D') when the FieldType is "D" and full value with valtype 'T' when the field type is 'T'.
I suggest you return FW_TTOD( <fieldvalue> ) when the FieldType is 'D' and FW_DTOT( <fieldvalue> ) when the field value is 'T'. We use this in our XBrowse, TDataRow and TRecSet so that users are insulated from this behavior.
We need to keep this in mind when preparing SQL statements comparing Dates.
For example, SELECT * WHERE INVDT BETWEEN '2015-04-01' AND '2015-04-30' may totally exclude all transactions that took place on 30th Apr 2015. Because this is actually translated as INVDT >= '2015-04-01 00:00:00' and INVDT <= '2015-04-30 00:00:00'. Naturally this query ignores transactions from '2015-04-30 00:00:00.001' till '2015-04-30 23:59:59.999'
This is just an example to show how deceptive can be date comparisons. In addition MS Sql server has a very awkward habit of storing '2014-04-01' internally as '2014-04-01 12:00:00' in the field.
So, the safer construct is SELECT * WHERE INVDT >= '2015-04-01' AND INVDT < '2015-05-01'. I still see many amatuers committing this mistake which turns out to be a blunder in real life situations.
I hope if you keep this points in mind, everything will work as expected.