| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Returns the name of a month from a date.
CMonth( <dDate> ) --> cMonthName
The function returns a character string holding the month name of <dDate>. When <dDate> is an empty date, the function returns a null string ("").
The CMonth() function converts a date value into the name of the corresponding month. Use CDoW() to obtain the weekday name as character value. Both functions are used to format date values in a textual way.
Note: xHarbour's national language support allows for returning the name of a month in various languages. Refer to HB_LangSelect() for selecting a language module.
| See also: | CDoW(), Date(), Day(), DoW(), DtoC(), HB_LangSelect(), Month(), StoD(), Year() |
| Category: | Conversion functions , Date and time |
| Source: | rtl\datec.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example uses a user defined function to fill an array
// with all month names abbreviated to the first three letters.
PROCEDURE Main
LOCAL aMonths := MonthNames(3)
// display all month names
AEval( aMonths, {|c| QOut(c) } )
RETURN
FUNCTION MonthNames( nLen )
LOCAL aArray[12]
LOCAL i, cDate, cMonth
FOR i:=1 TO 12
cDate := "2000" + PadL( i, 2, "0" ) + "01"
cMonth:= CMonth( StoD( cDate ) )
IF Valtype( nLen ) == "N"
aArray[i] := Left( cMonth, nLen )
ELSE
aArray[i] := cMonth
ENDIF
NEXT
RETURN aArray
http://www.xHarbour.com