Convert Month name (Jan, Feb...) into a digit?

Hi, im looking for an easy way to convert Month name into corresponding digit.
JS would work best i imagine ?
Im using “Data Driven” source of variables, and then i would like to take that and digitize it…

so how do i do that ?

Im terrible with JS :confused:

The Variable name is =“Month”, and the value = “October” (but obviously i want it done for all the 12 months)
So i do:

loadVars | data.csv

storeEval | var str=“${Month}”; var res=str.replace(“October”, “10”) | month_digit

this returns

[info] Expand variable ‘var str=“${Month}”; var res=str.replace(“October”, “10”)’ into ‘var str=“October”; var res=str.replace(“October”, “10”)’

[info] Store ‘null’ into ‘month_digit’

PLz help why is it Null ? :frowning:

Java has several native libs to do this:

im looking for a simple solution, dont even know how to put java into katalon recorder
storeEval references only JS code, how would i write command for it ?

This is one way of doing it:

runScript | window.monthsArray = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"] | |
store | Oct | monthName |
runScript | return window.monthsArray.indexOf('${monthName}'.toLowerCase()) + 1 | monthDigit |
echo | ${monthDigit} | |

Obviously you need to change how you populate the monthName variable and if you are using full month names then you will need to change the values in monthsArray.
Note that indexOf is case sensitive, so we make sure everything is lowercase.
Also note that JavaScript array indexes are zero-based , so we add 1 to the returned value of indexOf to get the correct number.

Other JavaScript methods can be found here

Im trying your solution verbatim, and it fails

[error] Error: TypeError: window.months is undefined

Sorry. My mistake. I’d renamed the array in the first runScript command, but hadn’t changed it in the second.

It should read:

runScript | return window.monthsArray.indexOf('${monthName}'.toLowerCase()) + 1 | monthDigit |