Function Month() Foundation

Converts a date value into the numeric calender month.

Syntax
Month( <dDate> ) --> nMonth
Parameters
<dDate>
<dDate> is the date expression to convert.
Return

The return value of Month() is an integer numeric value in the range of 0 to 12. An empty date (CtoD("")) results in 0.

Description

The conversion function Month() is one of three functions which extract single numeric values from a date value. The other functions are Day() and Year(). Month() is used when the numeric calender month is needed for calculations. To determine the month name from a date value, CMonth() is used.

Examples
Month()
// The example shows various results of the function Month(). 

PROCEDURE Main 

   ? Date()                         // result: 12/06/94 
   ? Month(Date())                  // result: 12 
   ? Month(Date()+ 30 )             // result: 1 
   ? Month( CtoD("") )              // result: 0 

RETURN 
Creation of Quarterly totals

// In this example the yearly sales are calculated 
// by quarter. 

PROCEDURE QuarterSales 
   LOCAL aSales := { 0, 0, 0, 0 }, nMonth 
   USE Sales NEW 

   DO WHILE .NOT. Eof() 
      nMonth := Month( Sales->Date ) 

      DO CASE 
      CASE nMonth <= 3 
         aSales[1] += Sales->Number 
      CASE nMonth <= 6 
         aSales[2] += Sales->Number 
      CASE nMonth <= 9 
         aSales[3] += Sales->Number 
      CASE nMonth <= 12 
         aSales[4] += Sales->Number 
      ENDCASE 

      SKIP 
   ENDDO 

   AEval( aSales, {|nSum,n| QOut(Str(n,1)+". Quarter:",nSum) } ) 

RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.