KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: A method to test for NULL Date or Time Variables
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: May 21, 2013

4D v11, v12, and v13 provides a way to test fields for their NULL state, Is field value Null, but there is no native function for testing the NULL state of a variable.

There is a way to test the NULL state of date and time variables, look at the result of the String command when using the constants "Blank if null date" or "Blank if null time".

The method below uses that result to provide a function that returns true if the variable is NULL and false if it is not.

If (True)
    If (False)
    //*****************************************************************************
    //
    // Is_DateOrTime_Var_Null($Var_P)
    //
    // Written by Charles Vass - 07/17/2009, 12:44
    //
    // Purpose: To test if a Date or Time variable is NULL
    //
    // $0 - BOOLEAN - Returned value (True or False)
    // $1 - POINTER - Pointer to the date or time variable to test
    //
    //
    //*****************************************************************************

    End if
    C_TEXT($MethodName_T)
    $MethodName_T:=Current method name
//===================== Declare Variables ==================================
//method_parameters_declarations

    C_BOOLEAN($0)
    C_POINTER($Var_P;$1)
//--------------------------------------------------------------------------------
// method_wide_constants_declarations
//--------------------------------------------------------------------------------
//local_variable_declarations

    C_LONGINT($Ndx)
    C_TEXT($Buf_T)

End if
//====================== Initialize and Setup ================================

$Var_P:=$1

//======================== Method Actions ==================================

$Ndx:=Type($Var_P->)
Case of
  : ($Ndx=Is Date )
    $Buf_T:=String($Var_P->;Blank if null date )
  : ($Ndx=Is Time )
    $Buf_T:=String($Var_P->;Blank if null time )
  Else
    ALERT("Unsupported Type")
End case

`======================== Clean up and Exit =================================

$0:=($Buf_T="")


Example use is below:

C_TIME($Time_H)
C_DATE($Date_D)
C_BOOLEAN($Bool_B)

$Bool_B:=Is_DateOrTime_Var_Null (->$Time_H)
$Bool_B:=Is_DateOrTime_Var_Null (->$Date_D)


Since no value has been assign to the variables, in each case the value returned is true.