# Error: String '' was not recognized as a valid DateTime

**URL:** <https://forum.uipath.com/t/error-string-was-not-recognized-as-a-valid-datetime/773517>\
**Category:** Help\
**Tags:** workflow-diff, question, studio, activities, system\
**Created:** [October 15, 2024, 9:25am UTC](https://forum.uipath.com/t/error-string-was-not-recognized-as-a-valid-datetime/773517 "2024-10-15T09:25:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajababu.mandapati](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rajababu.mandapati/32/496791_2.png) [@rajababu.mandapati](https://forum.uipath.com/u/rajababu.mandapati)\
**Post date:** [October 15, 2024, 9:25am UTC](https://forum.uipath.com/t/error-string-was-not-recognized-as-a-valid-datetime/773517/1 "2024-10-15T09:25:18Z")

</div>

Hi everyone,

I’m encountering an issue while trying to convert dates in different formats into a specific format (dd/MM/yyyy). I have dates in the following formats:

- 22/Oct/2024
- 06/22/2023
- 18.11.2023

When I attempt to convert them to the format `22/06/2024`, I’m getting this error: **Assign: String ‘’ was not recognized as a valid DateTime.**

i am using this method : Convert.ToDateTime(“26/6/2024”).ToString(“dd/MMM/yyyy”) still it is throwing error

---

<div class="post-metadata">

**Author:** ![Raymond\_Hui](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/raymond_hui/32/502623_2.png) [@Raymond\_Hui](https://forum.uipath.com/u/Raymond_Hui)\
**Post date:** [October 15, 2024, 9:31am UTC](https://forum.uipath.com/t/error-string-was-not-recognized-as-a-valid-datetime/773517/2 "2024-10-15T09:31:16Z")

</div>

Could you try below script?

```auto
DateTime.ParseExact("06/22/2023", "MM/dd/yyyy", CultureInfo.InvariantCulture)

```

---

<div class="post-metadata">

**Author:** ![rajababu.mandapati](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rajababu.mandapati/32/496791_2.png) [@rajababu.mandapati](https://forum.uipath.com/u/rajababu.mandapati)\
**Post date:** [October 15, 2024, 9:49am UTC](https://forum.uipath.com/t/error-string-was-not-recognized-as-a-valid-datetime/773517/3 "2024-10-15T09:49:13Z")

</div>

Hai  
Thanks Your response  
but i tried this method but it is not working  
DateTime.ParseExact(“06/22/2023”, “MM/dd/yyyy”, CultureInfo.InvariantCulture)  
i don’t have specific format i am getting diffarent formats but i want to convert "dd/mm/yyyy " this format only

---

<div class="post-metadata">

**Author:** ![ashokkarale](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashokkarale/32/474400_2.png) [@ashokkarale](https://forum.uipath.com/u/ashokkarale)\
**Post date:** [October 15, 2024, 9:56am UTC](https://forum.uipath.com/t/error-string-was-not-recognized-as-a-valid-datetime/773517/4 "2024-10-15T09:56:43Z")

</div>

@rajababu.mandapati,

Use this snippet. You can add all possible formats in the array and it will always give you output in “dd/MM/yyyy”

```auto
strOutputDate= DateTime.ParseExact(inputDateVariable, {"dd/MMM/yyyy","MM/dd/yyyy","dd.MM.yyyy"}, CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")

```

Learning Resource:

> [@ambulance sos \[FirstAid\] Datatable: Debug & Analysis invalid DateTime Strings / String to DateTime Parsing Issues](https://forum.uipath.com/t/firstaid-datatable-debug-analysis-invalid-datetime-strings-string-to-datetime-parsing-issues/418641):
>
> This FirstAid Tutorial will describe how DateTime parsing issues can be analyzed and handled. Click spoiler text when in a hurry: Example Assignment Following Excel data will be processed and the corresponding Quarter is to calculate for the particular task date Input data: [input\_raw] Quarter Calculation Quarter = CInt(Math.Ceiling(YourDateTimeVar.Month / 3 )) Initial Implementation tmpTaskDate = DateTime.ParseExact(row("Date").toString.Trim, "dd.MM.yyyy", CultureInf…

\*\*Added missed ToString format at the end.  
\*\*Added learning resource

---

<div class="post-metadata">

**Author:** ![lakshmi.mp](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lakshmi.mp/32/263533_2.png) [@lakshmi.mp](https://forum.uipath.com/u/lakshmi.mp)\
**Post date:** [October 15, 2024, 9:57am UTC](https://forum.uipath.com/t/error-string-was-not-recognized-as-a-valid-datetime/773517/5 "2024-10-15T09:57:14Z")

</div>

Hi @rajababu.mandapati ,  
Just add this format in the array and check once

Use this expression

`Datetime.ParseExact(D_format.trim,{“yyyy.MM.dd”,“yyyy-MM-dd"," MM-dd-yyyy",“dd-MM-yyyy”},System.Globalization.CultureInfo.Invariantculture,System.Globalization.DateTimeStyles.None).ToString(“dd/MM/yyyy”)`

 ![image](https://global.discourse-cdn.com/uipath/original/4X/0/3/d/03de0cf005c05d4ea9ce5f8a67f653dbdcbcec38.png)  
Go on adding the different types of date formats. Hope this helps. Please check and update  
Note: In the above expression D\_format is nothing but input date

---

<div class="post-metadata">

**Author:** ![lrtetala](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@lrtetala](https://forum.uipath.com/u/lrtetala)\
**Post date:** [October 15, 2024, 9:58am UTC](https://forum.uipath.com/t/error-string-was-not-recognized-as-a-valid-datetime/773517/6 "2024-10-15T09:58:37Z")

</div>

Hi @rajababu.mandapati

Can you try this

```auto
formattedDate = DateTime.ParseExact(dateString, {"dd/MMM/yyyy", "MM/dd/yyyy", "dd.MM.yyyy"}, 
                                           System.Globalization.CultureInfo.InvariantCulture, 
                                           System.Globalization.DateTimeStyles.None).ToString("dd/MM/yyyy")

```

Regards,

---

<div class="post-metadata">

**Author:** ![Gowtham\_K115](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gowtham_k115/32/269026_2.png) [@Gowtham\_K115](https://forum.uipath.com/u/Gowtham_K115)\
**Post date:** [October 15, 2024, 9:58am UTC](https://forum.uipath.com/t/error-string-was-not-recognized-as-a-valid-datetime/773517/7 "2024-10-15T09:58:38Z")

</div>

Hi @rajababu.mandapati

Try this way

**Str variable** = `DateTime.ParseExact("Yourinput",{"dd/MMM/yyyy","MM/dd/yyyy","dd.MM.yyyy"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("dd/MM/yyyy")`

Regards,  
Gowtham K

---

<div class="post-metadata">

**Author:** ![lakshmi.mp](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lakshmi.mp/32/263533_2.png) [@lakshmi.mp](https://forum.uipath.com/u/lakshmi.mp)\
**Post date:** [October 15, 2024, 10:12am UTC](https://forum.uipath.com/t/error-string-was-not-recognized-as-a-valid-datetime/773517/8 "2024-10-15T10:12:06Z")

</div>

Hi @rajababu.mandapati ,  
Refer this workflow  
[ConvertDate.zip](https://forum.uipath.com/uploads/short-url/hv2MCbkxqDAeuKMetOyMutgqldC.zip) (2.5 KB)  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/b/f/4/bf4eb8baad6f6c42262cc2297d54402db749f9bc.png)

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [October 15, 2024, 10:37am UTC](https://forum.uipath.com/t/error-string-was-not-recognized-as-a-valid-datetime/773517/9 "2024-10-15T10:37:05Z")

</div>

> [@lakshmi.mp](#):
>
> MM-dd-yyyy",“dd-MM-yyyy”}

in addition to above:  
A date like: 7th May 2024 - 07-05-2024

 ![The image shows a comparison between two different methods with their respective output dates highlighted and circled, illustrating how different date formats affect the parsed result. (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/1/7/f/17f5851d9563cd54f6bec2462af906ec8e506de2.png)

As 5th July 2024 - 05-07-2024 is ambigious to 7th May 2024 - 05-07-2024  
above approach cannot reliable handle all formats and prefers the first format match

We should keep this in mind. However in such a case, when ambiguous dates are expected, then we should detect and handle very carefully

---

<div class="post-metadata">

**Author:** ![rajababu.mandapati](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rajababu.mandapati/32/496791_2.png) [@rajababu.mandapati](https://forum.uipath.com/u/rajababu.mandapati)\
**Post date:** [October 15, 2024, 12:18pm UTC](https://forum.uipath.com/t/error-string-was-not-recognized-as-a-valid-datetime/773517/10 "2024-10-15T12:18:31Z")

</div>

thanks your information
