DateTime day of week int
DateTime DayOfWeek property allow us to get the day number of week from a datetime object. this DayOfWeek property value
type is System.DayOfWeek. the System.DayOfWeek value is an enumerated constant that indicates the day of the week of the
provided datetime object.
DayOfWeek enumeration ranges from Sunday to Saturday. so if the datetime object is Sunday then it returns 0 (zero), Monday 1, Tuesday 2 and so on when we cast the value to an integer. the return integer number start from zero. by this way we can get day number from a datetime object. finally we cast the return value to an integer value. we also can get the day name by using this DayOfWeek property.
The following .net c# example code demonstrate us how can we get the day number as an integer value from a datetime object in an asp.net application.
DayOfWeek enumeration ranges from Sunday to Saturday. so if the datetime object is Sunday then it returns 0 (zero), Monday 1, Tuesday 2 and so on when we cast the value to an integer. the return integer number start from zero. by this way we can get day number from a datetime object. finally we cast the return value to an integer value. we also can get the day name by using this DayOfWeek property.
The following .net c# example code demonstrate us how can we get the day number as an integer value from a datetime object in an asp.net application.
datetime-dayofweek-int.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//initialize a datetime variable with today
DateTime today = DateTime.Today;
Label1.Text = "today : " + today.ToLongDateString();
Label1.Text += "<br ><br />day of week as string: ";
Label1.Text += today.DayOfWeek.ToString();
//Sunday is first day of week
//get day number of week
int dayNumberOfWeek = (int)today.DayOfWeek;
Label1.Text += "<br ><br />day of week as number (integer): ";
Label1.Text += dayNumberOfWeek;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - datetime day of week int</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - datetime day of week int
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
Font-Names="Comic Sans MS"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="get day of week as number"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>

- How to get day from a DateTime
- How to check whether the given year is a leap year
- How to get the number of days in a given month
- How to add 1 month to a given DateTime object
- How to add weeks to a DateTime object
- How to check if a DateTime is between two given dates
- How to check if a DateTime is later than another date
- How to get the month name from month number
- How to get the first day of week
- How to get two DateTime objects difference in milliseconds