DateTime.DayOfWeek Property
Assembly: mscorlib (in mscorlib.dll)
The value of the constants in the DayOfWeek enumeration range from zero (indicating DayOfWeek.Sunday) to six (indicating 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.
The following code 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
import System.*;
class Sample
{
public static void main(String[] args)
{
// 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, (System.Boolean)(dt.get_DayOfWeek() == DayOfWeek.Thursday));
Console.WriteLine("The day of the week for {0:d} is {1}.", dt,
dt.get_DayOfWeek());
} //main
} //Sample
/*
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.
*/
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.