Export (0) Print
Expand All

DateTimeOffset.DayOfWeek Property

Updated: July 2008

Gets the day of the week represented by the current DateTimeOffset object.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public DayOfWeek DayOfWeek { get; }

Property Value

Type: System.DayOfWeek
One of the DayOfWeek values that indicates the day of the week of the current DateTimeOffset object.

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).

You can also display the weekday name of a particular date by using the "D" format specifier or the "dddd" custom format specifier. For example:

DateTimeOffset displayDate = new DateTimeOffset(2008, 1, 1, 13, 18, 00, 
                                                DateTimeOffset.Now.Offset);
Console.WriteLine("{0:D}", displayDate);  // Output: Tuesday, January 01, 2008                     
Console.WriteLine("{0:d} is a {0:dddd}.", 
                  displayDate);           // Output: 1/1/2008 is a Tuesday.

Note that the string returned by calling the ToString method of the DayOfWeek enumeration member that is returned by this property is not localized. To extract a string that contains the weekday name of the current culture or of a specific culture, call the ToString method with the "dddd" custom format specifier. For example, the following code displays the weekday name for a date using the fr-fr culture.

DateTimeOffset thisDate = new DateTimeOffset(2007, 6, 1, 6, 15, 0, 
                                             DateTimeOffset.Now.Offset);
string weekdayName = thisDate.ToString("dddd", 
                                       new CultureInfo("fr-fr")); 
Console.WriteLine(weekdayName);                  // Displays vendredi     

The following example displays the weekday name of the first day of each month of the year 2008.

DateTimeOffset startOfMonth = new DateTimeOffset(2008, 1, 1, 0, 0, 0, 
                                         DateTimeOffset.Now.Offset);
int year = startOfMonth.Year;
do 
{
   Console.WriteLine("{0:MMM d, yyyy} is a {1}.", startOfMonth, startOfMonth.DayOfWeek);
   startOfMonth = startOfMonth.AddMonths(1);
}
while (startOfMonth.Year == year);
// This example writes the following output to the console: 
//    Jan 1, 2008 is a Tuesday. 
//    Feb 1, 2008 is a Friday. 
//    Mar 1, 2008 is a Saturday. 
//    Apr 1, 2008 is a Tuesday. 
//    May 1, 2008 is a Thursday. 
//    Jun 1, 2008 is a Sunday. 
//    Jul 1, 2008 is a Tuesday. 
//    Aug 1, 2008 is a Friday. 
//    Sep 1, 2008 is a Monday. 
//    Oct 1, 2008 is a Wednesday. 
//    Nov 1, 2008 is a Saturday. 
//    Dec 1, 2008 is a Monday.      

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5 SP1, 3.0 SP1, 2.0 SP1

Date

History

Reason

July 2008

Added the range of DayOfWeek values and their underlying Int32 values.

Content bug fix.

Community Additions

ADD
Show:
© 2014 Microsoft