# Expression: Converting date format to string in Expression

**URL:** <https://forum.uipath.com/t/expression-converting-date-format-to-string-in-expression/533355>\
**Category:** Studio\
**Tags:** activities-panel, question, studio, system, activities\
**Created:** [April 6, 2023, 7:08pm UTC](https://forum.uipath.com/t/expression-converting-date-format-to-string-in-expression/533355 "2023-04-06T19:08:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sisay\_Dinku](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sisay_dinku/32/263491_2.png) [@Sisay\_Dinku](https://forum.uipath.com/u/Sisay_Dinku)\
**Post date:** [April 6, 2023, 7:08pm UTC](https://forum.uipath.com/t/expression-converting-date-format-to-string-in-expression/533355/1 "2023-04-06T19:08:54Z")

</div>

Hi team,

If this condition is full filled I want to reload data into the data table  
IF  
dt\_Test60days.AsEnumerable().Where(Function(x) CDate(x(“Start Dt”).ToString()).Date \>= New Date(Today.Year, Today.Month, 2) AndAlso CDate(x(“Start Dt”).ToString()).Date \<= New Date(Today.Year, Today.Month, 2).AddDays(59)).ToString.Count\>0

Reload to data table  
dt\_Test60days.AsEnumerable().Where(Function(x) CDate(x(“Start Dt”).ToString()).Date \>= New Date(Today.Year, Today.Month, 2) AndAlso CDate(x(“Start Dt”).ToString()).Date \<= New Date(Today.Year, Today.Month, 2).AddDays(59)).CopyToDataTable()

 ![image - 2023-04-06T150529.691](https://global.discourse-cdn.com/uipath/original/4X/f/9/9/f99a5d226fbfa4c4f0c4b97eb1c03017dc2116bb.png)

However, I receive the following error,

 ![image - 2023-04-06T150821.650](https://global.discourse-cdn.com/uipath/original/4X/2/1/6/21674b47b48b394e0786123a8765171086aacfd6.png)

Can anyone look into this? Thanks a lot!

---

<div class="post-metadata">

**Author:** ![arjunshenoy](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/arjunshenoy/32/404588_2.png) [@arjunshenoy](https://forum.uipath.com/u/arjunshenoy)\
**Post date:** [April 6, 2023, 7:23pm UTC](https://forum.uipath.com/t/expression-converting-date-format-to-string-in-expression/533355/2 "2023-04-06T19:23:44Z")

</div>

Hi @Sisay_Dinku

Please try this & let us know:

```auto
If dt_Test60days.AsEnumerable().Where(Function(x) DateTime.Parse(x("Start Dt").ToString()).Date >= New Date(Today.Year, Today.Month, 2) AndAlso DateTime.Parse(x("Start Dt").ToString()).Date <= New Date(Today.Year, Today.Month, 2).AddDays(59)).Count > 0 Then
    dt_Test60days.AsEnumerable().Where(Function(x) DateTime.Parse(x("Start Dt").ToString()).Date >= New Date(Today.Year, Today.Month, 2) AndAlso DateTime.Parse(x("Start Dt").ToString()).Date <= New Date(Today.Year, Today.Month, 2).AddDays(59)).CopyToDataTable()
End If

```

Hope this helps,  
Best Regards.

---

<div class="post-metadata">

**Author:** ![supermanPunch](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/supermanpunch/32/133652_2.png) [@supermanPunch](https://forum.uipath.com/u/supermanPunch)\
**Post date:** [April 6, 2023, 7:30pm UTC](https://forum.uipath.com/t/expression-converting-date-format-to-string-in-expression/533355/3 "2023-04-06T19:30:20Z")

</div>

Hi @Sisay_Dinku ,

The Error is because there is mostly Empty value in the `Start Dt` column.

To Handle this, we can perform a initial check and if it exists only we can perform the rest of the checks and get the filtered data.

Also, We an reduce the re-write of the expression by using a Data Row Array type variable :

1. Create a data row array variable, say `dr_Array`.
2. Next, use the Expression in the below way :

```auto
dr_Array = dt_Test60days.AsEnumerable().Where(Function(x)Not String.IsNullOrWhiteSpace(x("Start Dt").ToString) andAlso CDate(x("Start Dt").ToString()).Date >= New Date(Today.Year, Today.Month, 2) AndAlso CDate(x("Start Dt").ToString()).Date <= New Date(Today.Year, Today.Month, 2).AddDays(59)).ToArray

```

1. Next, Use an If Condition to check if the `dr_Array` contains any data. We can do it using the below Expression :

```auto
dr_Array.Any

```

1. Next, In the Then part of the If you can use the below Expression :

```auto
dt_Test60days = dr_Array.CopyToDatatable

```

In the Else Part, You can add the clone :

```auto
dt_Test60days = dt_Test60days.Clone

```

Thus we should be able to avoid the re-writing of the expression.

---

<div class="post-metadata">

**Author:** ![Sisay\_Dinku](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sisay_dinku/32/263491_2.png) [@Sisay\_Dinku](https://forum.uipath.com/u/Sisay_Dinku)\
**Post date:** [April 6, 2023, 7:45pm UTC](https://forum.uipath.com/t/expression-converting-date-format-to-string-in-expression/533355/4 "2023-04-06T19:45:26Z")

</div>

@arjunshenoy

I receive the following error this time

→ String was not recognized as a valid DateTime.
