DT.Compare

Previous  Next

 

cmp = DT.Compare( time1 AS STRING,

                  time2 AS STRING,

                  flags AS INTEGER = 0 ) AS INTEGER

 


 

Compares 2 datetime strings and returns:

 

-1   time1 < time2

0    time1 = time2

1    time1 > time2

 

You can select to compare only the date or time portion of a datetime string.

 

The following compare constants have been defined in MyBASIC2_ExtLib.BIS

 

' DateTime Compare Flags

CONST EL_DT_TIMEVALUEONLY        = 0x00000001

CONST EL_DT_DATEVALUEONLY        = 0x00000002

 

Example:

 

$LIBRARY "MyBASIC2_ExtLib"

$INCLUDE "MyBASIC2_ExtLib"

 

CLS

 

DIM strDate AS STRING

DIM strTime AS STRING

DIM strDT AS STRING

DIM iCmp AS INTEGER

 

strDT = DT.Format( "%c", 2020, 3, 3, 23, 59, 59 )

 

PRINT "Old Date: ";strDT,

PRINT "New Date: ";DT.GetCurrent(),

 

' Use Random Number Generator to test a comparison

SELECT CASE ROUND( RND * 2 )

  CASE 0:

     iCmp = DT.Compare( DT.GetCurrent(), strDT )

  CASE 1:

     iCmp = DT.Compare( strDT, DT.GetCurrent() )

  CASE 2:

     iCmp = DT.Compare( strDT, strDT )

ENDSELECT

 

SELECT CASE iCmp

  CASE -1:

     PRINT DT.GetCurrent();" is before ";strDT,

  CASE 0:

     PRINT strDT;" is the same time as ";DT.GetCurrent(),

  CASE 1:

     PRINT strDT;" is later than ";DT.GetCurrent(),

  CASE ELSE

     PRINT "System is either drunk or messed up !",

ENDSELECT

 

PRINT "[End]",

 

END