DateTime.DayOfWeek Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the day of the week represented by this instance.
public:
property DayOfWeek DayOfWeek { DayOfWeek get(); };
public DayOfWeek DayOfWeek { get; }
member this.DayOfWeek : DayOfWeek
Public ReadOnly Property DayOfWeek As DayOfWeek
An enumerated constant that indicates the day of the week of this DateTime value.
The following example demonstrates the DayOfWeek property and the System.DayOfWeek enumeration.
// This example demonstrates the DateTime.DayOfWeek property
using namespace System;
int main()
{
// Assume the current culture is en-US.
// Create a DateTime for the first of May, 2003.
DateTime dt = DateTime(2003,5,1);
Console::WriteLine( "Is Thursday the day of the week for {0:d}?: {1}", dt, dt.DayOfWeek == DayOfWeek::Thursday );
Console::WriteLine( "The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek );
}
/*
This example produces the following results:
Is Thursday the day of the week for 5/1/2003?: True
The day of the week for 5/1/2003 is Thursday.
*/
// This example demonstrates the DateTime.DayOfWeek property
open System
// Assume the current culture is en-US.
// Create a DateTime for the first of May, 2003.
let dt = DateTime(2003, 5, 1)
printfn $"Is Thursday the day of the week for {dt:d}?: {dt.DayOfWeek = DayOfWeek.Thursday}"
printfn $"The day of the week for {dt:d} is {dt.DayOfWeek}."
// This example produces the following results:
//
// Is Thursday the day of the week for 5/1/2003?: True
// The day of the week for 5/1/2003 is Thursday.
// This example demonstrates the DateTime.DayOfWeek property
using System;
class Sample
{
public static void Main()
{
// Assume the current culture is en-US.
// Create a DateTime for the first of May, 2003.
DateTime dt = new DateTime(2003, 5, 1);
Console.WriteLine("Is Thursday the day of the week for {0:d}?: {1}",
dt, dt.DayOfWeek == DayOfWeek.Thursday);
Console.WriteLine("The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek);
}
}
/*
This example produces the following results:
Is Thursday the day of the week for 5/1/2003?: True
The day of the week for 5/1/2003 is Thursday.
*/
' This example demonstrates the DateTime.DayOfWeek property
Class Sample
Public Shared Sub Main()
' Assume the current culture is en-US.
' Create a DateTime for the first of May, 2003.
Dim dt As New DateTime(2003, 5, 1)
Console.WriteLine("Is Thursday the day of the week for {0:d}?: {1}", _
dt, dt.DayOfWeek = DayOfWeek.Thursday)
Console.WriteLine("The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek)
End Sub
End Class
'
'This example produces the following results:
'
'Is Thursday the day of the week for 5/1/2003?: True
'The day of the week for 5/1/2003 is Thursday.
'
The value of the constants in the DayOfWeek enumeration ranges from DayOfWeek.Sunday to DayOfWeek.Saturday. If cast to an integer, its value ranges from zero (which indicates DayOfWeek.Sunday) to six (which indicates DayOfWeek.Saturday).
The DayOfWeek property returns an enumerated constant; it does not reflect a system's regional and language settings. To retrieve a string representing a localized weekday name for a particular date, call one of the overloads of the ToString method that includes a format
parameter and pass it either the ddd
or dddd
custom format strings. For details, see How to: Extract the Day of the Week from a Specific Date.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: