Tech Tip: A utility to return the month name, full or abbreviation, for a given date
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Mac & Win
Published On: May 8, 2015
Prior 4D Knowledgebase versions of this function, FN_MonthName, which depended on Get indexed string does not wotk in modern versions of 4D. The utility below will return either the full month name or its abbreviation.
UTIL_MonthName
If (True) If (False) Begin SQL /* Name: UTIL_MonthName Path: UTIL_MonthName Written by Charles Vass - 04/29/2015, 10:39 Purpose: Return the text month name of a date $0 - TEXT - Name or abbreviation of target month $1 - DATE - Date with tartget month $2 - BOOLEAN - TRUE = Abbreviation, FALSE = Full name */ End SQL End if C_TEXT($MethodName_T) $MethodName_T:=Current method name //===================== Declare Variables ================================== //method_parameters_declarations C_TEXT($0;$Name_T) C_DATE($Dt_D;$1) C_BOOLEAN($Abbr_B;$2) //-------------------------------------------------------------------------- //method_wide_constants_declarations //-------------------------------------------------------------------------- //local_variable_declarations C_LONGINT($Ndx;$SOA;$RIS;$Params_L) End if //====================== Initialize and Setup ================================ $Params_L:=Count parameters $Dt_D:=$1 If ($Params_L>1) $Abbr_B:=$2 End if //======================== Method Actions ================================== $Name_T:=String($Dt_D;Internal date long) If ($Abbr_B) $Name_T:=Substring($Name_T;1;3) Else $Name_T:=Substring($Name_T;1;Position(" ";$Name_T)-1) End if //======================== Clean up and Exit ================================= $0:=$Name_T |
Example useage:
// Get full month name
//
$Name:= UTIL_MonthName(Current date) |
-- or --
$Name:= UTIL_MonthName(Current date;False) |
// Get abbreviated month name
//
$Name:= UTIL_MonthName(Current date;True) |