Multiple '' Assign' expression for datetime value

Hi,

I am trying to achieve the following expression for a value that has been exported from Excel.
This value could have been 9-12-2022 or 09-12-2022. The first input would trigger an error for the following expression: DateTime.ParseExact(variable, “d-MM-yyyy”,system.Globalization.CultureInfo.InvariantCulture)

Is it possible to assign the expression with ‘or’

DateTime.ParseExact(variable, “dd-MM-yyyy”,system.Globalization.CultureInfo.InvariantCulture) OR DateTime.ParseExact(variable, “d-MM-yyyy”,system.Globalization.CultureInfo.InvariantCulture)

If i try it, i receive expression error that the type of Assign with ‘OR’ is not possible for datetime variable.

Appreciate the help!

@sirwa we couldn’t use or inside assign because it throw Boolean value.if you want to convert it into datetime go with first expression

Hi,

The following expression will work even if input day or month is 2 digits.

DateTime.ParseExact(variable, “d-M-yyyy”,system.Globalization.CultureInfo.InvariantCulture)

What error do you have? As there might be extra white space, can you try to use Trim as the following?

DateTime.ParseExact(variable.Trim, “d-M-yyyy”,system.Globalization.CultureInfo.InvariantCulture)

Regards,

Hi @sirwa

Yes its possible to give multiple formats and also please try using .trim to make sure you remove any extra spaces. Below code will work with multiple formats you can add more formats as well


datevalue = DateTime.ParseExact(”Your date variable”, {"MM/dd/yyyy","MM/d/yyyy","M/dd/yyyy","M/d/yyyy",system.Globalization.culturalinfo.invariantculture, ,System.Globalization.DateTimeStyles.None)

Cheers

Hi @sirwa

Keep a message box and print the YourString and check the format there if the format in the expression and the message box differ add the additional format in the expression like

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

You can simply add the any number of date formats inside the {“”,“”} and the formats should be separated by comma

The above expression will look into array of string and choose the apt format as per the input string and convert them and return you the output of desired format.

You can try with If activity

Regards
Gokul

Hello @sirwa

Have you tried with the Modify Date activity? If not give it a try.

image

Thanks

Thanks

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