Min and Max methods for DateTime

Math.Max Method doesn't have overload for DateTime
So I've created

        public static DateTime Min(DateTime t1, DateTime t2)

        {

            if (DateTime.Compare(t1, t2) > 0)

            {

                return t2;

            }

            return t1;

        }

        public static DateTime Max(DateTime t1, DateTime t2)

        {

            if (DateTime.Compare(t1, t2) < 0)

            {

                return t2;

            }

            return t1;

        }

 

posted @ Thursday, February 21, 2008 4:50 PM

Print

Comments on this entry:

# re: Min and Max methods for DateTime

Left by artykul8 at 10/5/2009 3:14 PM
Gravatar
or you can do a one-line implementation:

Max(t1, t2):
return DateTime.Compare(t1, t2) > 0 ? t1 : t2;

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345