Get Next Monday - CSharp System

CSharp examples for System:DateTime Day

Description

Get Next Monday

Demo Code


using System.Globalization;
using System;//from www.  j av a2 s .c  o m

public class Main{
        private static DateTime GetNextMonday()
        {
            DateTime tommorow = DateTime.Now.AddDays(1);
            int dayDifference = (int)tommorow.DayOfWeek - (int)DayOfWeek.Monday;
            if (dayDifference == 0)
            {
                return tommorow;
            }
            else if (dayDifference == -1)
            {
                //sutra je nedjelja
                return tommorow.AddDays(1);//now its monday
            }
            else
            {
                return tommorow.AddDays(7 - dayDifference);//now its monday
            }
        }
}

Related Tutorials