CSharp examples for System:DateTime Calculate
Checks whether a date time is between two date times.
// Copyright (c) Rico Suter. All rights reserved. using System;/*from w w w . j a va 2s .co m*/ public class Main{ /// <summary>Checks whether a date time is between two date times. </summary> /// <param name="dt">The date time to work with. </param> /// <param name="start">The starting date time. Null means undefinitely in the past. </param> /// <param name="end">The ending start time. Null means undefinitely in the future. </param> /// <returns>True when the date time is between. </returns> public static bool IsBetween(this DateTime? dt, DateTime? start, DateTime? end) { return dt.HasValue && dt.Value.IsBetween(start, end); } /// <summary> /// Checks whether a date time is between two date times. /// </summary> /// <param name="dt">The date time to work with. </param> /// <param name="start">The starting date time. Null means undefinitely in the past. </param> /// <param name="end">The ending start time. Null means undefinitely in the future. </param> /// <returns>True when the date time is between. </returns> public static bool IsBetween(this DateTime dt, DateTime? start, DateTime? end) { return (start == null || start.Value <= dt) && (end == null || dt < end.Value); } /// <summary>Checks whether a date time is between two date times. </summary> /// <param name="dt">The date time to work with. </param> /// <param name="start">The starting date time. </param> /// <param name="end">The ending start time. Null means undefinitely in the future. </param> /// <returns>True when the date time is between. </returns> public static bool IsBetween(this DateTime? dt, DateTime start, DateTime? end) { return dt.HasValue && dt.Value.IsBetween(start, end); } /// <summary>Checks whether a date time is between two date times. </summary> /// <param name="dt">The date time to work with. </param> /// <param name="start">The starting date time. </param> /// <param name="end">The ending start time. Null means undefinitely in the future. </param> /// <returns>True when the date time is between. </returns> public static bool IsBetween(this DateTime dt, DateTime start, DateTime? end) { return start <= dt && (end == null || dt < end.Value); } /// <summary>Checks whether a date time is between two date times. </summary> /// <param name="dt">The date time to work with. </param> /// <param name="start">The starting date time. </param> /// <param name="end">The ending start time. </param> /// <returns>True when the date time is between. </returns> public static bool IsBetween(this DateTime? dt, DateTime start, DateTime end) { return dt.HasValue && dt.Value.IsBetween(start, end); } /// <summary>Checks whether a date time is between two date times. </summary> /// <param name="dt">The date time to work with. </param> /// <param name="start">The starting date time. </param> /// <param name="end">The ending start time. </param> /// <returns>True when the date time is between. </returns> public static bool IsBetween(this DateTime dt, DateTime start, DateTime end) { return start <= dt && dt < end; } }