In one of the projects I was working on, I had to compare the current date to a date in future and disable a section(panel) of the aspx. page. This can be done with the code below.
DateTime oFixedDate = new DateTime(2012,7,15);//Constant Date.
Console.WriteLine("Fixed DateTime:" + oFixedDate.ToString());
Console.WriteLine("Today DateTime:" + DateTime.Now.ToString());
if (DateTime.Now.CompareTo(oFixedDate) > 0)
Console.WriteLine("Today is greater than the fixed date");
else if (DateTime.Now.CompareTo(oFixedDate) == 0)
Console.WriteLine("Today is equal to the fixed date");
else
Console.WriteLine("Today is less than the fixed date");
Output:
After changing the fixed date to
DateTime oFixedDate = new DateTime(2012,7,17);
DateTime oFixedDate = new DateTime(2012,7,15);//Constant Date.
Console.WriteLine("Fixed DateTime:" + oFixedDate.ToString());
Console.WriteLine("Today DateTime:" + DateTime.Now.ToString());
if (DateTime.Now.CompareTo(oFixedDate) > 0)
Console.WriteLine("Today is greater than the fixed date");
else if (DateTime.Now.CompareTo(oFixedDate) == 0)
Console.WriteLine("Today is equal to the fixed date");
else
Console.WriteLine("Today is less than the fixed date");
Output:
After changing the fixed date to
DateTime oFixedDate = new DateTime(2012,7,17);
No comments:
Post a Comment