# Date time Comparison

**URL:** <https://forum.uipath.com/t/date-time-comparison/766919>\
**Category:** Help\
**Tags:** activities-panel, question, studio, activities, system\
**Created:** [September 14, 2024, 4:26pm UTC](https://forum.uipath.com/t/date-time-comparison/766919 "2024-09-14T16:26:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![marina.dutta](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/marina.dutta/32/496759_2.png) [@marina.dutta](https://forum.uipath.com/u/marina.dutta)\
**Post date:** [September 14, 2024, 4:26pm UTC](https://forum.uipath.com/t/date-time-comparison/766919/1 "2024-09-14T16:26:26Z")

</div>

Hi,

I am doing date time comparison. I got the below date and time: getting both date and time equal but when comapring it shows false

str\_attached\_files\_date  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/6/1/3/613298a84717e531cdce37b580a4762086e661ca.png)

maxDate  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/1/4/1/1419a7a301cfd9daad0900b82fbdc3adc9869977.png)

 ![image](https://global.discourse-cdn.com/uipath/original/4X/7/5/b/75b07775d286aad1c4a3729760fa3ff99fda515b.png)  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/5/1/a/51ade87c940d070d1d0aec6ce02fbb36cb9ee22a.png)

---

<div class="post-metadata">

**Author:** ![Anjani\_Kapoor](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anjani_kapoor/32/385909_2.png) [@Anjani\_Kapoor](https://forum.uipath.com/u/Anjani_Kapoor)\
**Post date:** [September 14, 2024, 4:34pm UTC](https://forum.uipath.com/t/date-time-comparison/766919/2 "2024-09-14T16:34:19Z")

</div>

you may try the below expression:

str\_attached\_files\_date.tostring.trim.equals(maxDate.tostring.trim)

---

<div class="post-metadata">

**Author:** ![jast1631](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jast1631/32/499917_2.png) [@jast1631](https://forum.uipath.com/u/jast1631)\
**Post date:** [September 14, 2024, 4:38pm UTC](https://forum.uipath.com/t/date-time-comparison/766919/3 "2024-09-14T16:38:18Z")

</div>

Hi @marina.dutta Your second date value is having extra space between time and date  
Check once  
There is additional space between 2023 and 2:15

Regards,  
Jagravi

---

<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:** [September 14, 2024, 6:03pm UTC](https://forum.uipath.com/t/date-time-comparison/766919/4 "2024-09-14T18:03:28Z")

</div>

@marina.dutta,

Comparing date strings is not a good practice.

Convert the your datetime strings into date and then do the comparison.

Convert Files date to DateTime datatype variable:

`dtmFilesDate = DateTime.ParseExact(str_attached_files_date. Trim.Replace(" "c, ""), "M/d/yyyyh:mm", System.Globalization.CultureInfo.InvariantCulture)`

Convert Max Date to DateTime datatype:

`dtmMaxDate = DateTime.ParseExact(maxDate. Trim.Replace(" "c, ""), "M/d/yyyyh:mm", System.Globalization.CultureInfo.InvariantCulture)`

Now compare the date to date like this:

`dtmFilesDate=dtmMaxDate`

Thanks,  
Ashok 🙂

---

<div class="post-metadata">

**Author:** ![marina.dutta](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/marina.dutta/32/496759_2.png) [@marina.dutta](https://forum.uipath.com/u/marina.dutta)\
**Post date:** [September 14, 2024, 6:31pm UTC](https://forum.uipath.com/t/date-time-comparison/766919/5 "2024-09-14T18:31:41Z")

</div>

@ashokkarale

Actually my date is in last modified column. I need to find the latest date and time in Last Modified column

![image](https://global.discourse-cdn.com/uipath/original/4X/3/7/9/3799858d8c1b735a80d16c84425398972303bc43.png)

---

<div class="post-metadata">

**Author:** ![marina.dutta](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/marina.dutta/32/496759_2.png) [@marina.dutta](https://forum.uipath.com/u/marina.dutta)\
**Post date:** [September 14, 2024, 6:57pm UTC](https://forum.uipath.com/t/date-time-comparison/766919/6 "2024-09-14T18:57:41Z")

</div>

@ashokkarale

How can I compare the max date and time in the below format?

![image](https://global.discourse-cdn.com/uipath/original/4X/5/c/d/5cdc89a46e65e6b1b40ab139c997332d8b9c8d16.png)

---

<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:** [September 14, 2024, 6:58pm UTC](https://forum.uipath.com/t/date-time-comparison/766919/7 "2024-09-14T18:58:42Z")

</div>

@marina.dutta,

Ok in that case, use array. Add these datetime strings in an array and then sort the array.

Follow this thread for solution.

> [@Sort array of Date Time in descending order](https://forum.uipath.com/t/sort-array-of-date-time-in-descending-order/413189/3):
>
> Hi @Sairam_RPA , I am assuming that the format is day-month-year-time, and that there are only two different types of format and if that is the case, then here is an alternative solution → [image] First, we will declare an Array of Formats → arr\_strFormats = {"d/M/yyyy h:mm tt","dd.MM.yyyy h:mm tt"} Next, we will use an overload from the DateTime.ParseExact method that takes an array of formats as argument. To order the date in Ascending order, we simply have to order it, since the items…

---

<div class="post-metadata">

**Author:** ![marina.dutta](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/marina.dutta/32/496759_2.png) [@marina.dutta](https://forum.uipath.com/u/marina.dutta)\
**Post date:** [September 14, 2024, 7:20pm UTC](https://forum.uipath.com/t/date-time-comparison/766919/8 "2024-09-14T19:20:15Z")

</div>

@ashokkarale

Actually its a table where I need to download the the file with max date and to get the max date by  
I converted into data table and tried getting max date by

max date= ExtractDataTable\_Invoice.AsEnumerable().Max(Function (drRows) DateTime.Parse(drRows.Item(“Column-1”).ToString)).ToString

Then doing for each loop and checking if current date is equal to max date. But here I am getting in PM value .I dont need the PM

 ![image](https://global.discourse-cdn.com/uipath/original/4X/a/2/0/a20f676be2b7d6c847d611b68bf044b326d1c71e.png)

---

<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:** [September 14, 2024, 7:28pm UTC](https://forum.uipath.com/t/date-time-comparison/766919/9 "2024-09-14T19:28:50Z")

</div>

@marina.dutta

Then get the datetime and just convert as you need

`DateTime.ParseExact("ValueFromPage".Replace(" ",""),"M/d/yyyyh:mtt",System.Globalization.CultureInfo.InvariantCulture)`

Replacing space to ensure removal of extra spaces

Now if you need in any specific format use `.ToString("Format you need")`

Cheers

---

<div class="post-metadata">

**Author:** ![marina.dutta](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/marina.dutta/32/496759_2.png) [@marina.dutta](https://forum.uipath.com/u/marina.dutta)\
**Post date:** [September 14, 2024, 7:34pm UTC](https://forum.uipath.com/t/date-time-comparison/766919/10 "2024-09-14T19:34:37Z")

</div>

@Anil_G

I need the dates in format like 1/19/2023 2.14

can i do it as below:

DateTime.ParseExact(“str\_attached\_files\_date”.Replace(" “,”"),“M/d/yyyyh:mtt”,System.Globalization.CultureInfo.InvariantCulture).ToString(“M/d/yyyyh:mm”)

---

<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:** [September 15, 2024, 3:14am UTC](https://forum.uipath.com/t/date-time-comparison/766919/11 "2024-09-15T03:14:22Z")

</div>

@marina.dutta

Just add a space after yyyy and it should be good

Cheers

---

<div class="post-metadata">

**Author:** ![marina.dutta](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/marina.dutta/32/496759_2.png) [@marina.dutta](https://forum.uipath.com/u/marina.dutta)\
**Post date:** [September 15, 2024, 7:47am UTC](https://forum.uipath.com/t/date-time-comparison/766919/12 "2024-09-15T07:47:19Z")

</div>

@ashokkarale

the expression is not working for me.

I did in the below form

max\_date=DateTime.ParseExact(max\_date, “MM/dd/yyyy HH:mm:ss”, System.Globalization.CultureInfo.InvariantCulture).ToString(“M/d/yyyy h:mm”)

str\_attached\_files\_date= DateTime.ParseExact(str\_attached\_files\_date, “M/d/yyyy h:mm tt”, System.Globalization.CultureInfo.InvariantCulture).ToString(“M/d/yyyy h:mm”)

Then I did trim ,its working

max\_date.ToString.trim\>(str\_attached\_files\_date.ToString.trim)
