We help IT Professionals succeed at work.

how do you find the greater date  in .net ASP C#

tcmmaxt
tcmmaxt asked
on
Medium Priority
401 Views
Last Modified: 2012-05-12
expert:
I have 2 Datetime objects and want to find which date is greater. Once I find which date is greater,  I want to compare that date with todays date to see if it is greater or less or equal to today's date? Could someone please show me the C# code how to do this.
Comment
Watch Question

Technical Analyst
Commented:
Please have a look at this link:

http://msdn.microsoft.com/en-us/library/system.datetime.compare.aspx

Hope it helps you.
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015
Commented:
You could do something like this:

DateTime greater = (date1 > date2 ? date1 : date2);

Open in new window


Then you can compare "greater" using KaushalArora's link to figure its relationship with the current date.
Commented:
Try this:
DateTime dt1 = DateTime.Today;
DateTime dt2 = DateTime.MaxValue;
DateTime dt3 = DateTime.MinValue;
           
int intCompare = (DateTime.Compare(dt2, dt3) > 0 ? DateTime.Compare(dt1, dt2) : DateTime.Compare(dt1, dt3));

Author

Commented:
all thank you!!.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.