Gets the first week day following a date. - CSharp System

CSharp examples for System:DateTime Week

Description

Gets the first week day following a date.

Demo Code


using System.Collections.Generic;
using System;//from   ww w  .  j  a v a  2  s  .c om

public class Main{
        ///<summary>Gets the first week day following a date.</summary>
        ///<param name="date">The date.</param>
        ///<param name="dayOfWeek">The day of week to return.</param>
        ///<returns>The first dayOfWeek day following date, or date if it is on dayOfWeek.</returns>
        public static DateTime Next(this DateTime date, DayOfWeek dayOfWeek)
        {
            return date.AddDays((dayOfWeek < date.DayOfWeek ? 7 : 0) + dayOfWeek - date.DayOfWeek);
        }
}

Related Tutorials