4/11/2012

Compare two objects DateTime (C#)

Writing new method to reuse compare the date of two objects with below code

   1:  public static bool IsSameDayAs(DateTime a, DateTime b)
   2:  {
   3:    return a.Year == b.Year && a.Month == b.Month && a.Day == b.Day;
   4:  }

So now we can easy use the method like example

   1:  DateTime regDate = …
   2:   
   3:  if(regDate.IsSameDayAs(DateTime.Now)){
   4:    //do something or alert message
   5:  }

Categories: ,
If You Enjoyed This Post Please Take 5 Seconds To Share It.

0 comments:

Post a Comment

 
  • I'm a great believer that any tool that enhances communication has profound effects in terms of how people can learn from each other, and how they can achieve the kind of freedoms that they're interested in.

  • Followers