Changing month name to number with error

I’ve done this before and it’s worked without issue. I extract a date off of a PDF in the format of April 1, 2022. I want to convert April to 04. I’ve used the code datetime.parseextact(TrimeDate.trim(), “MMMM dd, yyyy”, System.Globalization,CultureInfo.InvariantCulture).ToString(“MM”).

When I debug i get the following error on that assign: Assign: String was not recognized as a valid DateTime.

How can I fix this?

Hi @atarantino,

Can you update the Assing content as follows?

Convert.ToDateTime(TrimDate,System.Globalization.CultureInfo.InvariantCulture).ToString("MM")

Regards,
MY

1 Like

Perfect, thank you.


kindly note the d instead of dd within the format definition

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