programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Tuesday, February 24, 2015 with c# example - datetime day of week

c# example - date time day of week:

DateTime DayOfWeek property allows 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 starts 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 application.

<!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; 
<html xmlns="">       
<head id="Head1" runat="server">       
    <title>c# example - datetime day of week int</title>       
    <form id="form1" runat="server">       
        <h2 style="color:MidnightBlue; font-style:italic;">       
            c# example - datetime day of week int 
        <hr width="550" align="left" color="Gainsboro" />       
            Font-Names="Comic Sans MS" 
        <br /><br />     
            Text="get day of week as number"