C# Program To Get Day Of The Week

Introduction

In this blog, you will learn how to create a program that shows a name for the weekday after the specific days. In this program, we take input from the user in the number of days and then show the date and weekday name by adding that day to the current date.

Code

using System;

namespace DayOfTheWeek
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("\t Program to get Day Of the Week After Specified Days");
            Console.WriteLine("\t ==================================================================");
            Console.Write("\t Enter Days After Today : ");
            int days=Convert.ToInt32( Console.ReadLine());
            DateTime date = DateTime.Now.AddDays(days);
            Console.WriteLine("\t Current Date : " + DateTime.Now.ToString("MM/dd/yyyy"));
            Console.WriteLine("\t Date After {0} Days : {1}", days, date.ToString("MM/dd/yyyy"));
            Console.WriteLine("\t Day Of The Week On {0} : {1}", date.ToString("MM/dd/yyyy"), date.DayOfWeek);
            Console.ReadKey();
        }
    }
}

Output

C# Program to Get Day Of The Week After Some Days

C# Program to Get Day Of The Week After Some Days

Explanation

  • In the above code, first, we take input from the user and convert that input into an integer.
  • Then we add that number of days in the current date by the AddDays method of DateTime data type.
  • Then we print the current date and date after those days. For the day of the week, we use the DayOfWeek property of the DateTime object.