Hi, Readers.
Today I would like to share another mini tip about Business Central, how to convert Month Name (Text) to Month Number (Integer). For example, I have the month name ‘January’, I would like to only show ‘1’.
Last month we discussed How to get the Month Name/Text from a date (Two ways).

Then I was asked if the reverse was possible, January -> 1. I performed a quick investigation and found that a standard method already exists for this.
codeunit 10 “Type Helper” -> procedure GetLocalizedMonthToInt:

Let’s look at a simple example.

Great.

Test video:
Test code:
pageextension 50112 CustomerCardExt extends "Customer Card"
{
layout
{
addafter(Name)
{
field(MonthText; MonthText)
{
ApplicationArea = All;
Caption = 'Month Text';
trigger OnValidate()
var
TypeHelper: Codeunit "Type Helper";
begin
Message('Month Name is %1\Month Number is %2', MonthText, TypeHelper.GetLocalizedMonthToInt(MonthText));
end;
}
}
}
var
MonthText: Text;
}Very simple, give it a try!!!😁
END
Hope this will help.
Thanks for reading.
ZHU



コメント