Assign: String was not recognized as a valid DateTime while trying to convert string to datetime data type

Hi Everyone,

I want to convert a value of CurrentRow (3/19/2024 4:00:05 PM) from type String to type DateTime. Using the expression- DateTime.ParseExact(DashboardDateTime,“dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture)
I have been trying it however encountering with an error, which I have mentioned below-

Please help me on this.

Thanks,
TIN RPA

Hi,

Can you try the following expression?

DateTime.ParseExact(DashboardDateTime,"M/d/yyyy h:m:s tt", System.Globalization.CultureInfo.InvariantCulture)

Regards,

have a look here for analysis techniques

Hi @TIN_RPA

You provided date format doesn’t matching your Input excel data. Your input date format is in M/dd/yyyy h:mm:ss tt but you have given dd/MM/yyyy. Just replace the format in your expression.

DateTime.ParseExact(DashboardDateTime,"M/dd/yyyy h:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture)

Just changed the highlighted part in your expression,
DateTime.ParseExact(DashboardDateTime,“dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture)

Hope it helps!!

1 Like

Hi @Yoichi,

Thank you very much for your prompt reply and yes it did work.

Regards,
TIN RPA

1 Like

Hi @mkankatala,

Yes, You are right. I was making a mistake which was causing that error. It has now working fine.

Thank you very much for your reply.

Best Regards,
TIN RPA

1 Like

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