Error message: Assign: String was not recognized as a valid DateTime

Hi everyone,

my bot reads a date from an excel file and tries to convert it.

I use an assign activity. The value to save goes as follows:

Convert.ToDateTime(Row(“Data”).ToString).ToString(“MM”, cultureInfo_Culture)+ “-” +Convert.ToDateTime(Row(“Data”).ToString).ToString(“yyyy”)

I am getting the error: “Assign: String was not recognized as a valid DateTime.”

Could someone kindly help me out here?

Thanks a lot in advance!

Hi @Anonym

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

Use this expression instead of convert.ToDateTime.

In place of “yyyy/MM/dd” put the input format.

Hope it helps.

Hi @Anonym

What is the excel format?

What you is the final result ?

How about this expression, You need to update the format based on the excel file

DateTime.ParseExact(Row(“Data”).ToString,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("dd-yyyy")

Hi @Harshith_Adyanthaya,

thank you for your swift response! With your suggestion, I am getting this error:

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

try this. U have used String in place of Row(“Data”).ToString

Hi @Gokul001 ,

thank you for your help!
The format in the excel is dd.MM.yyyy
The format I’d like to achieve in my bot is MM-yyyy

With your suggestion, I am still getting
image

Hi @Anonym ,

Try the following:

DateTime.ParseExact(Row(“Data”).ToString,"dd.MM.yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("MM-yyyy")

Regards,

Hi @Anonym

Give a try to this.

DateTime.ParseExact(Row("Data").ToString, "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MM-yyyy")

Hope this might help you.

Try with this below expression @Anonym

DateTime.ParseExact(Row(“Data”).ToString,"dd.MM.yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("MM-yyyy")

@Anonym

Most of the times when the data is read feom excel the dates are read in a different format than we see…so first please run the process and pause it after reading data and check the format from locas panel datatable variable…then it would be proper to convert

Generally if its a valid foat then datetime.Parse or cdate will work else we can use prseexact to specify the exact format

Cdate(datestring).ToString("MM-yyyy")

Hope this helps

Chwers

HI @Anonym

Try like this ?

DateTime.ParseExact(Row(“Data”).ToString.Trim,{"MM/dd/yyyy hh:mm:ss","dd.MM.yyyy","dd.MM.yyyy hh:mm:ss"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("MM-yyyy")

Regards
Sudharsan