KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Get quarter from given date
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: May 25, 2017

Below is an utility method to get the quarter from the given date.

// Method: DATE_GET_QUARTER
// $1 - Date
// $0 - Quarter date belongs to (1-4)
C_DATE($1;$date)
C_LONGINT($0;$m;$q)
If(Count parameters>=1)
   $date:=$1
   $m:=Month of($date)

   Case of
      : ($m>=1) & ($m<4)
         $q:=1
      : ($m>=4) & ($m<7)
         $q:=2
      : ($m>=7) & ($m<10)
         $q:=3
      Else
         $q:=4
   End case
   $0:=$q
End if


Example:

$q:=DATE_GET_QUARTER(!01/12/15!) //$q returns 1
$q:=DATE_GET_QUARTER(!05/12/15!) //$q returns 2
$q:=DATE_GET_QUARTER(!08/12/15!) //$q returns 3
$q:=DATE_GET_QUARTER(!11/12/15!) //$q returns 4