Error campo datetime en ADO con Harbour 3.2.0

Post Reply
Salvador
Posts: 142
Joined: Sun Dec 18, 2005 3:18 pm
Location: España

Error campo datetime en ADO con Harbour 3.2.0

Post by Salvador »

Hola,

En Harbour, realizando una comparación de 2 datetime cuando uno de ellos es un campo de ADO y la hora es 00:00, solo se comparan las fechas.

Este ejemplo devuelve .f.
hb_cTot( "14/03/16 12:23" ) > ::oRs:Fields("fecha"):Value // en la DB 14/03/16 00:00

Tiene alguien constancia de este problema ?

Estoy utilizando la version 3.2.0dev de Harbour

Gracias de antemano
Saludos
Salvador
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Error campo datetime en ADO con Harbour 3.2.0

Post by nageswaragunupudi »

hb_cTot( "14/03/16 12:23" )
Better you use century also. May be 14/03/16 is treated as 14/03/1916 instead of 14/03/2016.

Safest is to use hb_stot( "20160314122300" ) instead of hb_ctot()
Regards

G. N. Rao.
Hyderabad, India
Salvador
Posts: 142
Joined: Sun Dec 18, 2005 3:18 pm
Location: España

Re: Error campo datetime en ADO con Harbour 3.2.0

Post by Salvador »

Gracias por la sugerencia, como sugiere funciona correctamente.

Pero entonces me surgen estas dudas:

Si el campo de la DB contiene 2016-03-14 00:00

hb_datetime() > ::oRs:Fields("fecha"):Value , devuelve .f. para cualquier hora del día 2016-03-14
hb_valtostr(::oRs:Fields("fecha"):Value) devuelve "14/03/2016" (sin hora)

Si el campo de la DB contiene 2016-03-14 00:01 lo anterior funciona correctamente.
Saludos
Salvador
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Error campo datetime en ADO con Harbour 3.2.0

Post by nageswaragunupudi »

We should be careful (1) when comparing DateTime ( valtype T ) with Date ( valtyle D ) and also (2) know for sure that the value returned by fields(..):value is of type T or D. Unfortunately xHarbour and Harbour do not behave exactly the same way.

Try this test

Code: Select all

   d := date()
   t := hb_datetime() // datetime() in xharbour

   ? t > d, t < d, t == d
 
Harbour returns .f., .f., .f.
xHarbour returns .f., .f., .t.

My advice:
Convert both to DateTime types and compare:
We have two function FW_DTOT() and FW_TTOD()

example:
HB_DATETIME() > FW_DTOT( oRs:Fields( "date" ):Value )

If we are interested in the date part only then compare

FW_TTOD( <datetimevalue> ) > FW_TTOD( .... )
Regards

G. N. Rao.
Hyderabad, India
Salvador
Posts: 142
Joined: Sun Dec 18, 2005 3:18 pm
Location: España

Re: Error campo datetime en ADO con Harbour 3.2.0

Post by Salvador »

Con Harbour y SQL server:

Code: Select all

? valtype(::oRs:Fields("smalldatetime"):Value) // 2016-03-22 00:00:00.000 
? valtype(::oRs:Fields("smalldatetime"):Value) // 2016-03-22 10:30:15.000  
 
D
T

Es correcto ?
Saludos
Salvador
Post Reply