CSharp examples for System:DateTime Day
Returns true if the DateTime is within X number of days, false otherwise.
using System;//from w w w . j a v a2 s. c o m public class Main{ /// <summary> /// Returns true if the DateTime is within X number of days, false otherwise. /// </summary> /// <param name="dt"></param> /// <param name="days"></param> /// <param name="useUtc"></param> /// <returns></returns> public static bool IsWithinXDays(this DateTime dt, int days, bool useUtc = true) { DateTime past = DateTime.Today.AddDays(-days).ToUniversalTime(); if (!useUtc) past = DateTime.Today.AddDays(-days); return dt.CompareTo(past) >= 0; } }