C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






How to compare Dates.


Posted Date: 26 Jun 2008    Resource Type: Code Snippets    Category: Date & Time
Author: RohitMember Level: Gold    
Rating: Points: 10



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());





Responses

Author: Bunty    29 Jun 2008Member 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




Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: AddDays method of a DateTime object
Previous Resource: Convert seconds to minutes
Return to Discussion Resource Index
Post New Resource
Category: Date & Time


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use