DT.Get

Previous  Next

 

val = DT.Get( datetime AS STRING,

              part     AS STRING ) AS INTEGER

 


 

Returns the specified part of a date or time as an INTEGER.

 

Following parts are defined in MyBASIC2_ExtLib.BIS

 

' DateTime Parts

CONST EL_DT_Year                 = 1

CONST EL_DT_Month                = 2

CONST EL_DT_Day                  = 3

CONST EL_DT_Hour                 = 4

CONST EL_DT_Minute               = 5

CONST EL_DT_Second               = 6

 

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