Problem to convert date with error DateTime.Parse(Expiry_date).ToString("dd MMMM yyyy")

Error : Assign: String ‘’ was not recognized as a valid DateTime.

code :
Assign Activity
variable :Expiry_date
Value: DateTime.Parse(Expiry_date).ToString(“dd MMMM yyyy”)

Thank you in advance

1 Like

This shows your input string is empty. Can you check content of Expiry_date?

Regards,

1 Like

@madhavraichur25

as per error expirtdate variable is having empty string

cheers

1 Like

variable contain data in it

1 Like

no variable as string “15/03/2024”

1 Like

fine is 12/05/2018 is of format dd/MM/yyyy or MM/dd/yyyy
if its dd/MM/yyyy
then out_date = Datetime.ParseExact(“12/05/2019”,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
where out_date is a variable of type datetime

or if its of format “MM/dd/yyyy”
then
out_date = Datetime.ParseExact(“12/05/2019”,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)

1 Like

@madhavraichur25

the exception shows it is empty please checkthe same

String ‘’ was not recognized as a valid DateTime

cheers

1 Like

How did you check it? Can you check content of the variable in Locals panel when exception occurs in Debug mode?

1 Like

Hi @madhavraichur25

What is the format of Expiry_date. If it’s of format MM/dd/yyyy your code i.e. DateTime.Parse(Expiry_date).ToString("dd MMMM yyyy") will work.

If not use the below syntax:
Assign-> Expiry_date = "15/03/2024"

Assign-> Output = DateTime.ParseExact(Expiry_date.ToString,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("dd MMMM yyyy")

Please send an sample input so that I can help you.

Hope you understand!!

1 Like

Hi @madhavraichur25

Assign-> Expiry_date = "15/03/2024"

Assign-> Output = DateTime.ParseExact(Expiry_date.ToString,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("dd MMMM yyyy")

Check the below flow for better understanding:

Hope you understand!!

1 Like

I am getting the same error on code that I haven’t changed in months.

My testing suggests that the latest Community release has caused the issue since I have been using a string() (array of date format strings) variable in the ParseExact method e.g. DateTime.ParseExact(myDateTimeString,myDateTimeFormatStringArray, system.Globalization.CultureInfo.InvariantCulture) which has been working successfully for months until the recent upgrade which now gives the compile-time error “BC30311: Value of type ‘String()’ cannot be converted to ‘String’. The selected value is incompatible with the property type.”

When I attempt to convert the string() variable to a string using the myDateTimeFormatStringArray.ToString conversion method to stop the compile-time error, then I get the same error as @madhavraichur25 when I attempt to parse an actual string representation of a valid DateTime quantity.

The syntax that has been working for Months:
datetime.ParseExact(myDateToParseAsString,myDateFormatString,system.Globalization.CultureInfo.InvariantCulture)

The DateTimeFormat array value:

EDIT After additional testing: I believe the issue is that the prototype has changed from having an optional DateTimeStyle parameter to now requiring a DateTimeStyle if the format is an array of format strings. I used “DateTimeStyles.AdjustToUniversal”

1 Like