CSharp examples for System:TimeSpan
Get DateTime Range
using System.Linq; using System;//from www . j a va 2 s. c om public class Main{ public static DateTimeRange GetRange(DateTime? from, DateTime? to, int dayRange) { DateTime fromDate = DateTime.UtcNow.Date.AddDays(-dayRange); DateTime toDate = DateTime.UtcNow.Date.AddDays(+dayRange); if (from.HasValue) { fromDate = from.Value.Date; } if (to.HasValue) { toDate = to.Value.Date; } return new DateTimeRange(fromDate, toDate); } public static DateTimeRange GetRange(DateTime? from, DateTime? to) { return GetRange(@from, to, 1); } }