# Multiple '' Assign' expression for datetime value

**URL:** <https://forum.uipath.com/t/multiple-assign-expression-for-datetime-value/496453>\
**Category:** Studio\
**Tags:** assign, activities-panel, question, studio, excel, system, activities\
**Created:** [December 5, 2022, 10:20pm UTC](https://forum.uipath.com/t/multiple-assign-expression-for-datetime-value/496453 "2022-12-05T22:20:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sirwa](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sirwa/32/178116_2.png) [@sirwa](https://forum.uipath.com/u/sirwa)\
**Post date:** [December 5, 2022, 10:20pm UTC](https://forum.uipath.com/t/multiple-assign-expression-for-datetime-value/496453/1 "2022-12-05T22:20:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![sangeethaneelavannan1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sangeethaneelavannan1/32/176935_2.png) [@sangeethaneelavannan1](https://forum.uipath.com/u/sangeethaneelavannan1)\
**Post date:** [December 5, 2022, 11:03pm UTC](https://forum.uipath.com/t/multiple-assign-expression-for-datetime-value/496453/2 "2022-12-05T23:03:26Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [December 5, 2022, 11:21pm UTC](https://forum.uipath.com/t/multiple-assign-expression-for-datetime-value/496453/3 "2022-12-05T23:21:16Z")

</div>

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)

 ![image](https://global.discourse-cdn.com/uipath/original/4X/f/3/c/f3c7414cf3736ce89bfe00f0fe5f4d7c6338be28.png)

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,

---

<div class="post-metadata">

**Author:** ![Anil\_G](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anil_g/32/524291_2.png) [@Anil\_G](https://forum.uipath.com/u/Anil_G)\
**Post date:** [December 6, 2022, 2:30am UTC](https://forum.uipath.com/t/multiple-assign-expression-for-datetime-value/496453/4 "2022-12-06T02:30:16Z")

</div>

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

```auto

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

---

<div class="post-metadata">

**Author:** ![Gokul001](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gokul001/32/462734_2.png) [@Gokul001](https://forum.uipath.com/u/Gokul001)\
**Post date:** [December 6, 2022, 4:35am UTC](https://forum.uipath.com/t/multiple-assign-expression-for-datetime-value/496453/5 "2022-12-06T04:35:20Z")

</div>

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

```auto
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.

> [@sirwa](#):
>
> Assign with ‘OR’ is not possible for datetime variable.

You can try with If activity

Regards  
Gokul

---

<div class="post-metadata">

**Author:** ![Rahul\_Unnikrishnan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rahul_unnikrishnan/32/464046_2.png) [@Rahul\_Unnikrishnan](https://forum.uipath.com/u/Rahul_Unnikrishnan)\
**Post date:** [December 6, 2022, 5:29am UTC](https://forum.uipath.com/t/multiple-assign-expression-for-datetime-value/496453/6 "2022-12-06T05:29:34Z")

</div>

Hello @sirwa

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

![image](https://global.discourse-cdn.com/uipath/original/4X/5/2/3/523bb1ac9a6c01605073ea6661cc1c246445f55e.png)

[![](https://global.discourse-cdn.com/uipath/original/4X/7/6/c/76caa894b2e00d0c1f0225d6dac3a90e23e36c17.jpeg "How to Modify Date in UiPath? Modify Date activity explained with demo") ](https://www.youtube.com/watch?v=SlIqfo9D5no)

Thanks

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [December 14, 2022, 8:12pm UTC](https://forum.uipath.com/t/multiple-assign-expression-for-datetime-value/496453/7 "2022-12-14T20:12:38Z")

</div>

Closed on December 14, 2022, 8:12pm UTC

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