Getting error as "Format Value: Cannot convert Generic Value to System.DateTime"

Hi Team,
The scenario is I am getting the values from an excel file and storing as variable of type generic value.

Now when, I am trying to format the Generic value to date time MM/dd/YYYY then getting an error as Format Value: Cannot convert Generic Value to System.DateTime

Some one PLEASE HELP.Main.xaml (54.8 KB)

Use Parse Method to convert String to DateTime

Hi Sonal,
I am new to this as well as programming ! Could you help me out with the solution?

use the below assign activity

date_2=DateTime.ParseExact(date_1.ToString,“MM/dd/YYYY”,System.Globalization.CultureInfo.InvariantCulture)

where date_2 is the date format

date_1 is value retrived from excel

Regards,

Nived N
Happy Automation

1 Like

Read data from excel in a string type variable.
To do that go to the variables pane in the studio and change the variable type.

Now to parse the date use this in a assign if the input is in MM/dd/yyyy format only:
DateTime.ParseExact(yourvariable, “MM/dd/yyyy”(This is your input date value format), System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat).ToString(“MM/dd/yyyy”)

The variable to which you will assign this above statement’s value(the output) that should be a DateTime variable

1 Like


It’s displaying error like ‘)’ Expected

I think since it is showing no validation error

U can run it and check @Aakash_Paliwal


It’s displaying error like ‘)’ Expected

It is displaying error

Can you check none of the variables have GenericType from the variable pane.
varWeDate should be string, varFormateDate should be DateTime.

Now getting new error
“Get Row Item we_date: StringConverter cannot convert from System.DateTime.”
image

Worked for me.

Small change though.

Both the variables need to be strings.

Str1 = DateTime.ParseExact(yourvariable, “MM/dd/yyyy”, System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat).ToString(“MM/dd/yyyy”)

Str1 and yourvariable are both string types

1 Like

Thank You Sonal
It worked :slight_smile:

1 Like

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