Home » C#

C# | DateTime.DayOfWeek Property with Example

DateTime.DayOfWeek Property: Here, we are going to learn about the DayOfWeek Property of DateTime class with example in C#.
Submitted by IncludeHelp, on October 24, 2019

DateTime.DayOfWeek Property

DateTime.DayOfWeek Property is used to return the day of the week.

Syntax:

    DayOfWeek DateTime.DayOfWeek;

Return value:

The return type of this Property is DayOfWeek, It returns the day of the week.

Example to demonstrate example of DateTime.DayOfWeek Property

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //creating an object of DateTime class
            //and, initializing it with the current time 
            //using "Now"           
            DateTime dt = DateTime.Now;

            //getting day of the week
            string day = dt.DayOfWeek.ToString();

            //printing the day of the week
            Console.WriteLine("Day of the week is: " + day);

            //just to print a new line
            Console.WriteLine();
        }
    }
}

Output

Day of the week is: Thursday
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.