Returns true if the [TimeInQuestion] falls between the [StartTime] and the [EndTime] - CSharp System

CSharp examples for System:DateTime Time

Description

Returns true if the [TimeInQuestion] falls between the [StartTime] and the [EndTime]

Demo Code


using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from   ww w .  j  a v  a  2 s.  c o m*/

public class Main{
        /// <summary>
        /// Returns true if the [TimeInQuestion] falls between the [StartTime] and the [EndTime]
        /// </summary>
        /// <param name="TimeInQuestion">The time being checked</param>
        /// <param name="StartTime">Start of time window</param>
        /// <param name="EndTime">End of time window</param>
        /// <returns>boolean</returns>
        public static bool IsBetween(System.DateTime TimeInQuestion, System.DateTime StartTime, System.DateTime EndTime)
        {
            if (TimeInQuestion >= StartTime)
            {
                if (TimeInQuestion <= EndTime)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
}

Related Tutorials