# Convert string to Date and Compare

**URL:** <https://forum.uipath.com/t/convert-string-to-date-and-compare/123765>\
**Category:** Help\
**Tags:** activities, system\
**Created:** [June 10, 2019, 6:48am UTC](https://forum.uipath.com/t/convert-string-to-date-and-compare/123765 "2019-06-10T06:48:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mukeshkala](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mukeshkala/32/523935_2.png) [@mukeshkala](https://forum.uipath.com/u/mukeshkala)\
**Post date:** [June 10, 2019, 6:48am UTC](https://forum.uipath.com/t/convert-string-to-date-and-compare/123765/1 "2019-06-10T06:48:38Z")

</div>

Hi Experts ,

I have Date as **strInputDate : “23.08.2019”** - String.

I want to compare it with SystemDate.

Approach i used :

1. Replace . with /  
\_strInputDate.replace(“.”,“/”) - I got : 23/08/2019

2. Add Hours : just to make it valid datetime  
ValidThroDateAddHours = \_strInputDate + “” 11:06:30 AM"" – I got “23/08/2019 11:06:30 AM”

3. Next  
DateTime.ParseExact(ValidThroDateAddHours,“dd/MM/yyyy hh:mm:ss tt”,Nothing).ToString(“dd/MM/yyyy HH:mm:ss”)

Getting Error at Step 3 : Assign: String was not recognized as a valid DateTime.

Please Suggest what Am i doing wrong.

Also , if there any better alternative. all i want is to compare

string - “23.08.2019” with CurrentDate

Thanks

---

<div class="post-metadata">

**Author:** ![Palaniyappan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palaniyappan/32/524095_2.png) [@Palaniyappan](https://forum.uipath.com/u/Palaniyappan)\
**Post date:** [June 10, 2019, 6:58am UTC](https://forum.uipath.com/t/convert-string-to-date-and-compare/123765/2 "2019-06-10T06:58:22Z")

</div>

try like this buddy @mukeshkala

**StrOutputDate = Datetime.ParseExact(strInputDate,“dd.MM.yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)**

Then to compare this date with current date we can do like this  
but not with string datatype variable rather with datetime variable like this  
**DtOutputDate = Datetime.ParseExact(strInputDate,“dd.MM.yyyy”,System.Globalization.CultureInfo.InvariantCulture)**

Then you can compare like this to get the value you  
**DtOutputDate - Now**  
or  
**DtOutputDate \> Now**  
or  
**DtOutputDate \< Now**

Kindly try this and let know for any clarification or queries  
Cheers @mukeshkala

---

<div class="post-metadata">

**Author:** ![Palaniyappan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palaniyappan/32/524095_2.png) [@Palaniyappan](https://forum.uipath.com/u/Palaniyappan)\
**Post date:** [June 10, 2019, 8:03am UTC](https://forum.uipath.com/t/convert-string-to-date-and-compare/123765/3 "2019-06-10T08:03:03Z")

</div>

did that work buddy @mukeshkala

---

<div class="post-metadata">

**Author:** ![kalyanDev](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/kalyandev/32/68715_2.png) [@kalyanDev](https://forum.uipath.com/u/kalyanDev)\
**Post date:** [June 10, 2019, 8:08am UTC](https://forum.uipath.com/t/convert-string-to-date-and-compare/123765/4 "2019-06-10T08:08:30Z")

</div>

```auto
DateTime dt1=DateTime.ParseExact(strInputDate ,"MM-dd-yyyy",null);
DateTime dt2=Date.Today.ToShortDateString
int cmp=dt1.CompareTo(dt2);

   if(cmp>0) {
       // date1 is greater means date1 is comes after date2
   } else if(cmp<0) {
       // date2 is greater means date1 is comes after date1
   } else {
       // date1 is same as date2
   }

```

Try like this

---

<div class="post-metadata">

**Author:** ![mukeshkala](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mukeshkala/32/523935_2.png) [@mukeshkala](https://forum.uipath.com/u/mukeshkala)\
**Post date:** [June 10, 2019, 8:23am UTC](https://forum.uipath.com/t/convert-string-to-date-and-compare/123765/5 "2019-06-10T08:23:43Z")

</div>

@Palaniyappan

Awesome Bro 🙂 That Worked Perfectly !!

Kudos to you !!

---

<div class="post-metadata">

**Author:** ![Palaniyappan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palaniyappan/32/524095_2.png) [@Palaniyappan](https://forum.uipath.com/u/Palaniyappan)\
**Post date:** [June 10, 2019, 8:24am UTC](https://forum.uipath.com/t/convert-string-to-date-and-compare/123765/6 "2019-06-10T08:24:52Z")

</div>

Fantastic @mukeshkala  
Kindly close this topic with right comment marked as solution that could help others as well looking for ideas under your topic  
Cheers @mukeshkala

---

<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:** [June 13, 2019, 8:25am UTC](https://forum.uipath.com/t/convert-string-to-date-and-compare/123765/7 "2019-06-13T08:25:09Z")

</div>

Closed on June 13, 2019, 8:25am UTC

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