Get month name when input month number

nandanak

New Member
Is there any built in function in OpenEdge to get Month name when I input month number.
Ex : Input : 03 , Output : March
 

Cringer

ProgressTalk.com Moderator
Staff member
I don't think so, but this is easy to implement.
Code:
FUNCTION fn-MonthName RETURNS CHARACTER
  (INPUT ip-MonthNumber AS INTEGER):
  DEFINE VARIABLE lv-Months as CHARACTER NO-UNDO INITIAL "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".
  IF ip-MonthNumber LT 1 OR ip-MonthNumber GT 12 THEN
    RETURN "".
  RETURN ENTRY(ip-MonthNumber,lv-Months).
END.
 

magomg

New Member
Hi people!
I solved this problem using the ENTRY function as below:
DEFINE VARIABLE dt-prazo AS DATE NO-UNDO.

ASSIGN dt-prazo = 10/17/2024.

MESSAGE ENTRY(MONTH(dt-prazo),"JAN,FEV,MAR,ABR,MAI,JUN,JUL,AGO,SET,OUT,NOV,DEZ")
VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.

this way will show the month like "OUT".

I hope that is functional for you!

Regards...
 

Cecil

19+ years progress programming and still learning.
Or for something completlly different.:
Code:
using System.*.
using System.Globalization.*.

define variable monthNumber    as integer   no-undo.
define variable monthName      as character no-undo.
        
assign
    monthNumber = 3 // Example month number
    monthName = System.Globalization.CultureInfo:CurrentCulture:DateTimeFormat:GetMonthName(monthNumber).       
        
message Substitute("Month name for month number &1: &2", monthNumber, monthName)
    view-as alert-box information.

1713502783707.png
 

Osborne

Active Member
Cecil, for a .NET solution your example is a good one as it shows it can be achieved with just a single line of code:

Code:
MESSAGE System.Globalization.CultureInfo:CurrentCulture:DateTimeFormat:GetMonthName(3) VIEW-AS ALERT-BOX INFORMATION.

I had previously been using something similar to this:

Code:
DEFINE VARIABLE oDateTimeFormatInfo AS System.Globalization.DateTimeFormatInfo NO-UNDO.

oDateTimeFormatInfo = NEW System.Globalization.DateTimeFormatInfo().
MESSAGE oDateTimeFormatInfo:GetMonthName(3) VIEW-AS ALERT-BOX INFORMATION.
 
I like more the array approach ...
Code:
DEF VAR meses AS CHAR EXTENT 12 INIT ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
NO-UNDO.
DISPLAY meses[1]
 
Top