DayOfWeek Enum
Definition
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.
Specifies the day of the week.
public enum class DayOfWeek
public enum DayOfWeek
[System.Serializable]
public enum DayOfWeek
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum DayOfWeek
type DayOfWeek =
[<System.Serializable>]
type DayOfWeek =
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type DayOfWeek =
Public Enum DayOfWeek
- Inheritance
- Attributes
Fields
Name | Value | Description |
---|---|---|
Sunday | 0 | Indicates Sunday. |
Monday | 1 | Indicates Monday. |
Tuesday | 2 | Indicates Tuesday. |
Wednesday | 3 | Indicates Wednesday. |
Thursday | 4 | Indicates Thursday. |
Friday | 5 | Indicates Friday. |
Saturday | 6 | Indicates Saturday. |
Examples
The following example demonstrates the DateTime.DayOfWeek property and the 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
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
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
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.
'
Remarks
The DayOfWeek enumeration represents the day of the week in calendars that have seven days per week. The value of the constants in this enumeration ranges from Sunday to Saturday. If cast to an integer, its value ranges from zero (which indicates Sunday) to six (which indicates Saturday).
This enumeration is useful when it is desirable to have a strongly typed specification of the day of the week. For example, this enumeration is the type of the property value for the DateTime.DayOfWeek and DateTimeOffset.DayOfWeek properties.
The members of the DayOfWeek enumeration are not localized. To return the localized name of the day of the week, call the DateTime.ToString(String) or the DateTime.ToString(String, IFormatProvider) method with either the "ddd" or "dddd" format strings. The former format string produces the abbreviated weekday name; the latter produces the full weekday name.