Determines whether the specified date is in the weekend. - CSharp System

CSharp examples for System:DateTime Week

Description

Determines whether the specified date is in the weekend.

Demo Code


using System;/*from ww  w .j a va 2  s  .  c om*/

public class Main{
        /// <summary>
        ///     Determines whether the specified date is in the weekend.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static bool IsWeekend(this DateTime date)
        {
            bool isWeekend = date.IsSaturday() || date.IsSunday();
            return isWeekend;
        }
        /// <summary>
        ///     Determines whether the specified date is sunday.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static bool IsSunday(this DateTime date)
        {
            DayOfWeek dayOfWeek = date.DayOfWeek;
            bool isSunday = dayOfWeek == DayOfWeek.Sunday;
            return isSunday;
        }
        /// <summary>
        ///     Determines whether the specified date is saturday.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static bool IsSaturday(this DateTime date)
        {
            DayOfWeek dayOfWeek = date.DayOfWeek;
            bool isSaturday = dayOfWeek == DayOfWeek.Saturday;
            return isSaturday;
        }
}

Related Tutorials