Error campo datetime en ADO con Harbour 3.2.0

Error campo datetime en ADO con Harbour 3.2.0

Postby Salvador » Tue Mar 15, 2016 10:46 am

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
Salvador
 
Posts: 144
Joined: Sun Dec 18, 2005 3:18 pm
Location: España

Re: Error campo datetime en ADO con Harbour 3.2.0

Postby nageswaragunupudi » Thu Mar 17, 2016 7:47 am

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
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Error campo datetime en ADO con Harbour 3.2.0

Postby Salvador » Mon Mar 21, 2016 10:52 am

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
Salvador
 
Posts: 144
Joined: Sun Dec 18, 2005 3:18 pm
Location: España

Re: Error campo datetime en ADO con Harbour 3.2.0

Postby nageswaragunupudi » Mon Mar 21, 2016 1:41 pm

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  Expand view
  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
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Error campo datetime en ADO con Harbour 3.2.0

Postby Salvador » Tue Mar 22, 2016 9:57 am

Con Harbour y SQL server:

Code: Select all  Expand view

? 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
Salvador
 
Posts: 144
Joined: Sun Dec 18, 2005 3:18 pm
Location: España


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Horizon and 90 guests