KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Quickly determine the difference between two dates
PRODUCT: 4D | VERSION: 13.1 | PLATFORM: Mac & Win
Published On: September 20, 2012

Here is quick utility method that can be used to calculate the difference (in days) between two dates:

// returns the number of days between two dates
// always returns a positive value
C_DATE($1;$start;$2;$end)
C_LONGINT($0;$dif)
If (Count parameters=2)
   $start:=$1
   $end:=$2
   $dif:=$start-$end // calculate difference
   If ($dif<0) // if negative
      $dif:=$dif*-1 // make positive
   End if
   $0:=$dif //return difference
End if


If the above is code is stored in your database as UTIL_DaysBetween it can be used like this:

ALERT(String(UTIL_DaysBetween (Current date;!10/23/2012!)))


or:

ALERT(String(UTIL_DaysBetween (!10/23/2012!;Current date)))


The benefit of this method is that in all situations the value of 'days between' will be positive.