Convert integer to month like function MONTH() in excel
Application Type
Traditional Web

Hallo All,


How can i get Number of month on OutSystems like in function MONTH in excel eg(30 = 1, 95 = 4)


Regards,

Kane

Hi Kane

Try this one (NumDays is integer variable which will be number of days you want to use for example 95 )

Month(AddDays(NewDate(Year(CurrDate()),1,1),NumDays-1))

Hello Kane,

You can create your own static entity Months and depend on order of each record not Id because sometimes when you deploy static entity from one environment to another Ids become different . You can use aggregate to select month name by number (order = yourNumber) or select number (order) by month name (Label =yourMonthName ).

You can also create your own server action which take string month name as input and return month number as output using switch case inside or vise versa if you want to use number as input and return month name as output

If you have a date and you want to get month full name of that date you can try FormatDateTime built in function for example FormatDateTime(currdate(),"MMMM")


Hi,


How can I calculate my day integer to return month(1-12) with this methode?

Can you explain more details?


Thanks

Hi Kane,

OutSystems has built-in feature of  SQL Query. Here I called a SQL aggregate & returning month number & name with passing dynamic date. Please find attached screenshot for better understanding. 

Here '@Date' as 'Date' data type is query parameter where you can pass your dynamic date as per your requirements. And please add a structure with this parameters.

Number as 'Integer' & Name as 'Text'.

This is my approach of getting value from the output of SQL. It will reduce the time of implementing static entities & switch condition. 

Thanks.

Hi Sameer,

This is a SQL  Server built in function not OutSystems function because once you start using Advanced SQL you can write any SQL query using syntax of your database engine. This will work fine with SQL and syntax may be little bit different if you are using Oracle.

This way will work fine if you return month name in one language but you have to take care of localization if you are using multi-languages (as in my case we have Arabic and English)

Hi Sameer,

I don't want to use sql widget because in my case to resolve calculation this issue i use inside Aggregate.

Thanks.

Hi Kane,

Hope both the approach will help you to fulfill your requirements. If our approaches are not covering your requirements then please mention we will be happy to help you.

Thanks.

Hi Kane,

In your case, you can go with Mostafa approach but rather calling switch condition just add a filter to the aggregate "MONTH('DYNAMIC DATE') = MONTHS.ORDER". this filter provide you single data of Months aggregate.

Hope this may help you.

Hi Sameer,

FYI, day integer it's just number of days and i want to convert that number to month.

Hi Kane

Try this one (NumDays is integer variable which will be number of days you want to use for example 95 )

Month(AddDays(NewDate(Year(CurrDate()),1,1),NumDays-1))
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.