15,882,055 members
See more:
Dear Sir

I want to compare two dates which is in dd/MM/YYYY string format

Ankita Mali
Posted
Updated 1-Aug-11 18:37pm
v2

## Solution 1

You can use DateTime.Parse()[^] method to convert the string to a DateTime value and then after that, the compare is pretty straightforward.

## Solution 7

Simply convert the strings to `DateTime` objects, and then use the `==` operator to compare them:

C#
```DateTime dt1;
DateTime dt2;

if (DateTime.TryParse(strDate1, out dt1) && DateTime.TryParse(strDate2, out dt2))
{
if (dt1.Date == dt2.Date)
{
// the dates are identical
}
}```

## Solution 2

Convert both to `DateTime` and then use `DateTime.Compare` to do the comparison

v2
UJimbo 1-Aug-11 7:52am
1 star? Really?
walterhevedeich 1-Aug-11 7:56am
I think your solution is correct. Countered with a 5.
[no name] 1-Aug-11 8:15am
There are trolls who keep downvoting answers without even understanding what it means. Countered with 5.
UJimbo 1-Aug-11 8:19am
Thank you gentlemen

## Solution 6

Suppoese two textboxes as dtpReqDate and tpIssueDate.
DateTime(int year,int month,int day)
so break the string according to the above parameteres.

C#
```DateTime dtEndDate = new DateTime(int.Parse(dtpReqDate.Text.Substring(6, 4)), int.Parse(dtpReqDate.Text.Substring(0, 2)), int.Parse(dtpReqDate.Text.Substring(3, 2)));
DateTime dtStartDate = new DateTime(int.Parse(dtpIssueDate.Text.Substring(6, 4)), int.Parse(dtpIssueDate.Text.Substring(0, 2)), int.Parse(dtpIssueDate.Text.Substring(3, 2)));

TimeSpan devDate = dtStartDate.Subtract(dtEndDate);```

v2
walterhevedeich 1-Aug-11 7:59am
My 4. There's a shorter solution for it so that you dont need to go through all pain of the int conversions. You can do a Convert.ToDateTime, as others have pointed out, or DateTime.Parse.

## Solution 3

Hi,
Compare after conversion.
Use `Convert.ToDateTime("05/12/1984");`

v2
walterhevedeich 1-Aug-11 7:55am
Correct.
Ankita Mali 2-Aug-11 0:29am
but my date is in dd/MM/yyyy format if the date is 28/05/2011 it is giving error

## Solution 5

Hi,
C#
```if (date1.Equals(date2))
{

}
```

for checking equlaity..
do you want to take the diffrence in date?

for doing that convert those dates to datetime format and compare it

regards,
shefeek

v3
walterhevedeich 1-Aug-11 8:00am
Correct.
#realJSOP 1-Aug-11 8:07am
Your code is incorrect. The Equals method returns true if the objects are the same object (essentially, the same pointer value), not if the data represented by those objects is identical.
[no name] 1-Aug-11 8:19am
You are wrong John. DateTime is a value type and it's Equal method has been overriden to compare values.

## Solution 4

YYYYMMdd string format is easy to compare, but Permalink gives you the elegant and usefull way to compare dates