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 Expand view
#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:
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 )