Page 1 of 1

Sobre Cadenas de Tiempo

Posted: Tue Apr 26, 2011 4:11 pm
by JavierVital
Hola a todos, ojala alguien ya haya pasado por esto.

Mi cliente me pide que le muestre las notas de venta de 2 horas atras en cualquier horario
en mi tabla tengo un campo de texto con la hora en que se hicieron las notas
como puedo filtrarlas ?

si alguien me pudiera echar la mano.
De antemano muchas gracias.

Re: Sobre Cadenas de Tiempo

Posted: Tue Apr 26, 2011 5:55 pm
by armando.lagunas
Hola

no se si te sirva pero yo en una ocasión tuve que hacer esto con el calculo de horas extras, y lo que hice fue calcular los minutos de la hora que me devolvía la función time()

sería algo asi:

Code: Select all


// nMinActual recoje los minutos transcurridos de la hora del computador

nMinActual := (val(strtran(substr(TIME(),1,2)," ","0"))*60 ) + val(strtran(substr(TIME(),4,2)," ","0"))

// nHaceDosHoras recoje el valor de de los minutos, restando 2 horas en minutos

nHaceDosHoras := nMinActual - 120 


 
bueno obtienes los minutos transcurridos en una variable en la cual puedes filtrar en el campo de tu tabla.

se me ocurre de esta forma:

Code: Select all


nMindelcampo := (val(strtran(substr(field->campohora,1,2)," ","0"))*60 ) + val(strtran(substr(field->campohora,4,2)," ","0"))

IF nMindelCampo = nHaceDosHoras
   .....
   // lo que necesites hacer
   .....
ENDIF

 
espero haberte ayudado.

saludos

Re: Sobre Cadenas de Tiempo

Posted: Tue Apr 26, 2011 6:10 pm
by carlos vargas
creo recordar que xharbour y harbour ya manehjan el tipo de dato time, e incluso tiene funciones para manipulacion de horas.
DateTime() --> dDateTime
TtoS( <dDateTime>) --> cYYYYMMDDhhmmss.ccc
StoT( [<cDateTime>] ) --> dDateTime

Code: Select all

// The example outlines basic operations with DateTime values and
// lists their results.

   PROCEDURE Main
      LOCAL d1, d2, nDiff

      SET CENTURY ON
      SET TIME FORMAT TO "hh:mm:ss.ccc"

      ? DateTime()                      // result: [today] [systemtime]
      ? {ˆ 2007/04/26}                  // result: 04/26/2007
      ? {ˆ 05:30:12.345}                // result: 12/30/1999 05:30:12.345
      ? {ˆ 05:30:12.345 PM}             // result: 12/30/1999 17:30:12.345

      ** Empty value
      ? d1 := {ˆ 0/0/0 }                // result:   /  /
      ? Empty( d )                      // result: .T.

      ** difference between DateTime and Date
      ? d1 := {ˆ 2007/04/26 18:30:00 }  // result: 04/26/2007 18:30:00.000
      ? d2 := StoD("20070426")          // result: 04/26/2007
      ? nDiff := d1-d2, "days"          // result: 0.77 days
      ? TString( nDiff*86400 )          // result: 18:30:00

      ** Adding 2 days to DateTime
      ? d1 + 2                          // result: 04/28/2007 18:30:00.000

      ** Adding 2 hours to DateTime
      ? d1 + 2/24                       // result: 04/26/2007 20:30:00.000

      ** Adding 2 minutes to DateTime
      ? d1 + 2/(24*60)                  // result: 04/26/2007 18:32:00.000

      ** Adding 2 seconds to DateTime
      ? d1 + 2/(24*3600)                // result: 04/26/2007 18:30:02.000

   RETURN

 

Re: Sobre Cadenas de Tiempo

Posted: Tue Apr 26, 2011 6:55 pm
by JavierVital
Gracias Carlos

Lo solucione asi : Agrege un campo que se llama segundos numerico, y ahora cada vez que se guarda una nota se guardan los _
los _ de la cadena de tiempo fue asi : hora * 60 * 60 lo minutos solo por 60
y sume los 3 y obtube los segundos totales

en el filtro

Code: Select all

        nTime := RETORNA_SEGUNDOS(Time())  // aqui obtengo el los segundos pero en horas le resto 2
    cFiltro2 := "NOTASS->CAJA='"+AllTrim(aGENERAL[3])+"'"
    cFiltro1 := "NOTASS->SEGUNDOS >= "+AllTrim(Str(ntime))  
    cFiltro := "{||"+cFiltro2+" .AND. "+cFiltro1+"}"
    gFiltro := '"'+cFiltro2+' .AND. '+cFiltro1+'"'
    DbSetfilter(&cFiltro,&gFiltro)
 
solo asi.

Re: Sobre Cadenas de Tiempo

Posted: Tue Apr 26, 2011 7:43 pm
by karinha
Javier, podrias muestrar esta función?

RETORNA_SEGUNDOS(Time())

Gracias, salu2

Re: Sobre Cadenas de Tiempo

Posted: Thu Apr 28, 2011 4:52 pm
by JavierVital

Code: Select all

FUNCTION RETORNA_SEGUNDOS(cTiempo)
    LOCAL nHora, nMinu, nSegu
    nHora := ((Val(SubStr(cTiempo,1,2))-2)*60)*60
    nMinu := Val(SubStr(cTiempo,4,2))*60
    nSegu := Val(SubStr(cTiempo,7,2))
RETURN (nHora+nMinu+nSegu)
 

Re: Sobre Cadenas de Tiempo

Posted: Fri Apr 29, 2011 2:56 am
by nageswaragunupudi
Both Harbour and xHarbour provide DateTime type. DBFCDX provides FieldType "T" to store DateTime values. It is now time for us to totally giveup the old complicated calculation with character value of Time().

In the following sample, I created a DBF with field type "T" and filled with some datetime values. While browsing I set the Scope Top to current time less 2 hours.

Code: Select all

#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"
#include "hbcompat.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local oDlg, oBrw, oFont

   RDDSETDEFAULT( "DBFCDX" )
   SET DATE ITALIAN
   SET CENTURY ON
   SET TIME FORMAT TO "HH:MM"

   CreateTestDBF()

   USE TESTDTIM
   SET ORDER TO TAG TIMSTAMP
   SET SCOPETOP TO ( DateTime() - 2/24 )   // 2/24 = 2 hours
   GO TOP

   XBROWSER TITLE TTOC( DateTime() )

return nil

//----------------------------------------------------------------------------//

static function CreateTestDbf()

   field TIMSTAMP, TEXT

   local aCols := { ;
      { "TIMSTAMP",  "T",  8, 0  }, ;
      { "TEXT",      "C",  20,0  } }

   local t     := DateTime() - 5/24

   DBCREATE( "TESTDTIM", aCols )

   USE TESTDTIM EXCLUSIVE

   do while t < DateTime()
      APPEND BLANK
      TIMSTAMP    := t
      TEXT        := ATail( HB_ATokens( TTOC( t ), " " ) ) + ;
                     " Some text"
      t           += 1/24/4   // 1/24/4 = 15 minutes
   enddo

   INDEX ON TIMSTAMP TAG TIMSTAMP
   CLOSE TESTDTIM

return nil

//----------------------------------------------------------------------------//
 
Result:
Image

In the above sample, I used FieldType "T", because I filled up different datetime values manually.

DBFCDX provides another FieldType "@". This field holds DateTime values, but we should not write to this field. DBFCDX automatically fills this field with the time the record is written automatically.

In real life, we may use "@" field type and let DBFCDX automatically record the time of writing the Data, instead of the program writing the timestamp. ( Note: xHarbour is working perfectly, but I found the my Harbour version does not fill this field correctly )

Re: Sobre Cadenas de Tiempo

Posted: Fri Apr 29, 2011 4:22 pm
by carlos vargas
hi, nageswaragunupudi

i delete lines of code with fwh calls, pure xharbour code.

Code: Select all

    #include "ord.ch"

    REQUEST DBFCDX

    //----------------------------------------------------------------------------//

    function Main()

       local oDlg, oBrw, oFont

       RDDSETDEFAULT( "DBFCDX" )
       SET DATE ITALIAN
       SET CENTURY ON
       SET TIME FORMAT TO "HH:MM"

       CreateTestDBF()

       USE TESTDTIM
       SET ORDER TO TAG TIMSTAMP
       SET SCOPETOP TO ( DateTime() - 2/24 )   // 2/24 = 2 hours
       GO TOP
       browse()

    return nil

    //----------------------------------------------------------------------------//

    static function CreateTestDbf()

       field TIMSTAMP, TEXT
       local aCols := { ;
          { "TIMSTAMP",  "T",  8, 0  }, ;
          { "TEXT",      "C",  20,0  } }

       local t  := DateTime() - 5/24

       DBCREATE( "TESTDTIM", aCols )

       USE TESTDTIM EXCLUSIVE
       
       
       do while t < DateTime()

          APPEND BLANK
          TIMSTAMP    := t
          TEXT        := ATail( HB_ATokens( TTOC( t ), " " ) ) + ;
                         " Some text"
          t           += 1/24/4   // 1/24/4 = 15 minutes
       enddo

       INDEX ON TIMSTAMP TAG TIMSTAMP
       CLOSE TESTDTIM
       wait
    return nil

 
fail in this line

do while t < DateTime()
this is the info error:

Arguments .........: [ 1] = Type: N Val: 2455681.43 [ 2] = Type: T Val: Type: T

1 param: value 2455681.43
2 param: value 29/04/2011 10:18:00

compiling you code (full, no delete lines, incude call to fwh lib), fails, the datetime function no return value ?????
fails with apis mix between fwh and xharbour???

Re: Sobre Cadenas de Tiempo

Posted: Sat Apr 30, 2011 7:26 am
by nageswaragunupudi
I understand you are using Harbour ( not xHarbour ). Please comfirm.

DateTime() is function available in xHarbour.
Corresponding function in Harbour is HB_DateTime(). You may change DateTime() to HB_DateTime()

I included "hbcompat.ch". This include file translates DateTime() as HB_DateTime() if we are compiling with Harbour and translates HB_DateTime() as DateTime() if we are compiling with xHarbour.

similarly
HB_TTOC() and HB_CTOT() in Harbour are same as TTOC() and CTOT() in xHarbour.

Either you may hardcode these functions specially for Harbour or better you include the file "hbcompat.ch".

I compiled and tested my sample both with xHarbour and Harbour using the include file "hbcompat.ch".

While compiling with Harbour I also include xhb.lib and hbct.lib.

Note: I am not sure if the native ( Clipper compatible ) Browse() function in Harbour can handle new datatypes.

FWH's xBrowse() function handles all datatypes and all datasources.

Re: Sobre Cadenas de Tiempo

Posted: Sat Apr 30, 2011 4:49 pm
by carlos vargas
not, i use the last version from xharbour.com
:-(

salu2
carlos vargas

Re: Sobre Cadenas de Tiempo

Posted: Sun May 01, 2011 5:23 am
by nageswaragunupudi
I have built exactly the sample posted by you in xHarbour ( without fivewin ) 1.2.1 build 6733 ( downloaded from free.xharbour.com ) and the exe runs without any errors:

Here is the output:

Image

Re: Sobre Cadenas de Tiempo

Posted: Mon May 02, 2011 12:44 pm
by Maurizio
hi, nageswaragunupudi

if I compile xbrowse.prg I have this

Compiling 'C:\FWH_04\MY_FW\xbrowse.prg' and generating preprocessed output to 'C:\FWH_04\MY_FW\xbrowse.ppo'...
c:\Harbour\include\hbcompat.ch(266) Warning W0002 Redefinition or duplicate definition of #define GTI_WINDOW
c:\Harbour\include\hbcompat.ch(267) Warning W0002 Redefinition or duplicate definition of #define GTI_SCREEN
c:\Harbour\include\hbcompat.ch(268) Warning W0002 Redefinition or duplicate definition of #define GTI_CLIENT
c:\Harbour\include\hbcompat.ch(269) Warning W0002 Redefinition or duplicate definition of #define GTI_MAX
c:\Harbour\include\hbcompat.ch(338) Warning W0002 Redefinition or duplicate definition of #define HB_GTI_CLIPBOARDPAST

Regards Maurizio

Re: Sobre Cadenas de Tiempo

Posted: Mon May 02, 2011 5:17 pm
by nageswaragunupudi
Here it is compiling without any warnings in both xHarbour and Harbour.
Please make sure that your compile script does not include any other include files other than those included inside the xbrowse.prg.