By using following code, we can compare the two days. we are storing the dates in a string and then first splitting the string into an array and then comapre the dates.
DateTime dtTimeMinDate = new DateTime(); string strDateTime = "01/31/2007,01/01/2007,01/01/2008"; string [] arrDateTime = strDateTime.Split((new char[]{','})); if (arrDateTime != null && arrDateTime.Length > 0) { for (int iCount = 0; iCount < arrDateTime.Length; ++iCount) { DateTime dtTimeT1 = Convert.ToDateTime(arrDateTime.GetValue(iCount)); for (int jCount = iCount + 1; jCount < arrDateTime.Length; ++jCount) { DateTime dtTimeT2 = Convert.ToDateTime(arrDateTime.GetValue(jCount)); int i = DateTime.Compare(dtTimeT1, dtTimeT2); if (i > 0) { //Second date is min then the first dtTimeMinDate = dtTimeT2; break; } } } } MessageBox.Show("Minimum Date: " + dtTimeMinDate.Date.ToString());
|
| Author: Bunty 29 Jun 2008 | Member Level: Diamond Points : 2 |
Hi,
Very nice piece of code on how to compare two dates.
Easy to understand.
Keep posting such useful code.
Thanks for sharing your knowledge.
Thanks and Regards S.S.Bajoria
|