Wednesday 8 October 2014

How to Compare Two Calender Days in Asp.Net C#

No comments    
categories: , ,
Calenders Compare


                      DEMO




Html Coding


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>

        <tr><td>Calender1</td><td>
            <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
            </td></tr>
        <tr><td>calender2</td><td>
            <asp:Calendar ID="Calendar2"
 runat="server"
OnSelectionChanged="Calendar2_SelectionChanged">
</asp:Calendar>
            </td></tr>
        <tr><td colspan="2"><asp:Label ID="Label1"
 runat="server" Text="Output"></asp:Label>
            <asp:TextBox ID="TextBox1" runat="server"
BackColor="#FFFF66" TextMode="Week"></asp:TextBox>
            </td></tr>
       

    </table>
    </div>
    </form>
</body>
</html>


C# Coding


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Calender : System.Web.UI.Page
{
    DateTime date1, date2;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Calendar2_SelectionChanged(object sender, EventArgs e)
    {

        date1 = Convert.ToDateTime(Calendar1.SelectedDate);
        date2 = Convert.ToDateTime(Calendar2.SelectedDate);
        double days = (date2 - date1).TotalDays;
        TextBox1.Text = Convert.ToString(days);
    }
}

















                                      

0 comments:

Post a Comment