Issue - String was not recognized as a valid DateTime

Hello,
I have read and tried a few things but I keep getting the same error for the dates. I get the dates from an Excel file which are written there as dd/MM/yyyy and I want the bot to write them out as dd.MM.yyyy, but I can’t do this because instead of dd/MM/yyyy the bot sees the input as MM/dd/yyyy.
I tried using the following:

DateTime.ParseExact(in_PaymentStartDate, “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString

DateTime.ParseExact(in_PaymentStartDate.ToString, “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture)

Convert.ToDateTime(in_PaymentStartDate, System.Globalization.CultureInfo.GetCultureInfo(“hi-IN”).DateTimeFormat)

DateTime.ParseExact(in_PaymentStartDate, “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture)

but I couldn’t test some of these options due to this error
image

Hi @Dea_Pahumi ,

The internal representation of the Date varies at times, and hence we would need to observe what are the different formats that are presented either by using the Debug Panel or a Write line activity.

As you have mentioned the format seems to appear in MM/dd/yyyy, this is supposed to be the normal representation format.

So we could directly use the CDate() method for this case.

CDate(in_PaymentStartDate).ToString("dd.MM.yyyy")

But we also see that the error is because you are trying to assign a Date time type to a String variable.

The above suggested method should solve this.

Let us know if you still get errors.

1 Like

DateTime.ParseExact(in_PaymentStartDate.ToString, "MM/dd/yyyy", nothing).toString("dd.MM.yyyy)

1 Like

Hi @Dea_Pahumi

Since the BOT reads the data as MM/dd/yyyy, try using this once:

DateTime.ParseExact(in_PaymentStartDate.ToString,“MM/dd/yyyy”, Globalization.CultureInfo.InvariantCulture).ToString(“dd.MM.yyyy”)

Hope this helps,
Best Regards.

1 Like

for my case in particular this was the solution, thank you!

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