How to convert name month in number?

Hi everyone,

i know my question is similar like this How to convert Month(Text) into number? , but I tried to follow this link but as a result it gives me the following error:

Screenshot_3

How can i do that? Or are there any other ways to convert the month’s name into number?

Thanks in advance

Hi @salvatore.quimi,

Firstly parse the string to convert the string to valid Date format like below.

A = DateTime.ParseExtract(“29.05.2015”,“dd.MM.yyyy”,new CultureInfo(“en-US”));

Then get the Month as number like below.

A.ToString(“MM”)

Warm Regards,
Ranjith Udayakumar

Hi @salvatore.quimi

image

Output :-
image

Hope this help you to solve your query.
Make as a solution and like it if it helps you.:slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

hi @ranjith_udayakumar, I agree with you but if I already only have the month like my example:

Screenshot_4

and second assing = Datetime.ParseExact(month,“MMMM”,System.Globalization.CultureInfo.InvariantCulture).ToString(“MM”).

How can i convert the month’s name into number?

1 Like

Hi @salvatore.quimi

Use .month as i have shown above

Hope this help you to solve your query.
Make as a solution and like it if it helps you.:slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

hi @Pratik_Wavhal, thanks for your suggestion I wanted to ask if you know if I use this method for example: “Now.AddMonths(-1).ToString(“MMMM”, System.Globalization.CultureInfo.CreateSpecificCulture(“it”)).ToString” i know I find the previous month but if we were in January with this method, the result will be December?

Hi @salvatore.quimi,

You can use the same approach,

month = ‘July’
A = DateTime.ParseExtract(“29"+ month+"2015”,“dd.MMMM.yyyy”,new CultureInfo(“en-US”));
A.Month

It will give December.

Warm Regards,
Ranjith Udayakumar

Thank you, I’m trying but A what kind of variable is it?

Hi @salvatore.quimi,

month - String
A - DateTime

Warm Regards,
Ranjith Udayakumar

I’m looking but I don’t find datetime, could you tell me the full datetime path, please?

In any case if I find my month with this method “Now.AddMonths(-1).ToString(“MMMM”, System.Globalization.CultureInfo.CreateSpecificCulture(“en”))", then can I use it in the function you suggested me “A = DateTime.ParseExtract(“29”+ month+“2015”,“dd.MMMM.yyyy”,new CultureInfo(“en-US”))”?

thanks in advance

Hi @salvatore.quimi,

I think I am confusing you. Kindly share the input and output as you expected clearly. Then I can share the steps clearly.

Warm Regards,
Ranjith Udayakumar

Please dont input your personal info here.

Sure, Edited

he is right @bcorrea , you do not share personal info, if you want I can upload an example

First I want to find the previous month with this method ----> Now.AddMonths(-1).ToString(“MMMM”, System.Globalization.CultureInfo.CreateSpecificCulture(“en”))

Then once I find the month I want to convert it to number.

Is it possible? thank you

I found a solution: first i find previous month with this method ----> firstVariableString = Now.AddMonths(-1).ToString(“MMMM”, System.Globalization.CultureInfo.CreateSpecificCulture(“en”))

then i use other assign activity:
secondVariableString = Datetime.ParseExact(firstVariableString.ToString ,“MMMM”,System.Globalization.CultureInfo.InvariantCulture).ToString(“MM”)

thank you all for your support

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.