[edit] C# DateTime DayOfWeek Property
The DateTime DayOfWeek property simply returns a DayOfWeek object (Sunday through Saturday). We will show two ways to use the DayOfWeek property.
[edit] Syntax
DayOfWeek variable = DateTime.Now.DayOfWeek;
string d1 = DateTime.Now.DayOfWeek.ToString();
[edit] Example 1
using System;
class Program
{
static void Main()
{
DateTime d1 = DateTime.Now.Date;
Console.WriteLine(d1.ToString());
Console.Read();
}
}
Output:
Monday
The output will vary depending on when you run this program.
[edit] Example 2
This example will directly convert to DayOfWeek object to a string on the same line
using System;
class Program
{
static void Main()
{
string d1 = DateTime.Now.DayOfWeek.ToString();
Console.WriteLine(d1.ToString());
Console.Read();
}
}
Output:
Monday
<= DateTime Tutorial
|