How to convert String data to integer data

1
Hi, I am trying to convert string(‘Jan’, ‘Feb’, ’Mar’,….) to integer(1,2,3,….) in microflow how to do this, Please help me.  
asked
5 answers
2

You can use an if-else construction in a variable for this use-case.

answered
2

Hi Pranaya,

You can use this construction:

if $string = ‘Jan’ then 1
elseif $string = ‘Feb’ then 2
elseif $string = ‘Mar’ then 3

etc etc

answered
1

Pranaya, probably slightly better then Bob fine solution, since there are on average less:

parseInteger(substring('0001002003004005006007008009010011012',find($String,'JanFebMarAprMayJunJulAugSepOctNovDec')+1,3))

Sometimes i miss the good old high-coding days.

Or maybe you like this option better:

parseInteger(formatDateTimeUTC(parseDateTimeUTC($String,'MMM'),'MM'))

It first does parseDateTime to your string, making it a datetime. Then throws a formatDateTime to it to get a string, and then converts that string to an integer.

If you use this in a ‘Create variable’-activity, you best add an errorHandler catching the errors if String is not one of the twelve months.

Did a performance test on the three solution options. Bobs solution and the highcode are about the same. Using the functions, makes it about 50% slower.

 

answered
0

Did it work Pranaya?

answered
0

no Bob Boons, Actually I am trying to find data based on filters and In the retrieve data the month wise like from 'Jan' to 'Dec' data should show for that I am using oql query 
"select  SUM(R."UnitsSold")as UnitsSum,
              R."SEGMENT", DATEPART ( MONTH, R."Date") as Months,
              DATEPART ( YEAR, R."Date") as Years
from  Single_Selection_Charts.Realistic R 
where  R."Year" = $Year
GROUP BY R."SEGMENT", Months,Years
order by Months"

I am able to get data but month are integer type like 1,2,3....

this is my domain model 

this is my page 

this is my microflow  calling on search button

this is my output but in months cloumn I need Jan, Feb, … instead of 1,2,3… can help with this

answered