/ Published in: C#

This snippets regards a couple of extension methods to verify if a specified datetime is into a range.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#region DATETIME /// <summary> /// Verify if a datetime is in a range /// </summary> /// <param name="dateToCompare">The date to compare</param> /// <param name="Left">The left datetime in the range</param> /// <param name="Right">The right datetime in the range</param> /// <remarks>The range will include the left and the right datetime specified</remarks> /// <returns>Returns true if the datetime compared is into the range specified</returns> public static bool BetweenInclusive(this DateTime dateToCompare, DateTime Left, DateTime Right) { bool result = (dateToCompare.CompareTo(Left) >= 0) && (dateToCompare.CompareTo(Right) <= 0); return result; } /// <summary> /// Verify if a datetime is in a range /// </summary> /// <param name="dateToCompare">The date to compare</param> /// <param name="Left">The left datetime in the range</param> /// <param name="Right">The right datetime in the range</param> /// <remarks>The range will exclude the left and the right datetime specified</remarks> /// <returns>Returns true if the datetime compared is into the range specified</returns> public static bool BetweenExclusive(this DateTime dateToCompare, DateTime Left, DateTime Right) { bool result = (dateToCompare.CompareTo(Left) > 0) && (dateToCompare.CompareTo(Right) < 0); return result; } #endregion
Comments
