Count number of alternate Monday between two Dates in ASP.Net using C# and VB.Net

Last Reply 21 days ago By pandeyism

Posted 21 days ago

Hello Sir,

I want to calculate the count of alternate mondays in the given range in


You are viewing reply posted by: pandeyism 21 days ago.
Posted 21 days ago Modified on 20 days ago

Hey democloud,

Please refer below sample and refer below article.

AJAX Calendar Extender control with Time in ASP.Net


<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.dynDateTime.min.js" type="text/javascript"></script>
<script src="Scripts/calendar-en.min.js" type="text/javascript"></script>
<link href="Styles/calendar-blue.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(document).ready(function () {
            showsTime: true,
            ifFormat: "%m/%d/%y",
            daFormat: "%l;%M %p, %e %m, %Y",
            align: "BR",
            electric: false,
            singleClick: false,
            displayArea: ".siblings('.dtcDisplayArea')",
            button: ".next()"
    <asp:TextBox ID="TextBox1" runat="server" ReadOnly="true" class="test"></asp:TextBox>
    <img src="calender.png" alt="blank" />
    <asp:TextBox ID="TextBox2" runat="server" ReadOnly="true" class="test"></asp:TextBox>
    <img src="calender.png" alt="blank" />
    <asp:Button ID="btnSave" runat="server" Text="Count" OnClick="btnSave_Click" />
    <asp:GridView ID="gvDayes" runat="server" AutoGenerateColumns="false">
            <asp:BoundField DataField="Days" HeaderText="Days" />
            <asp:BoundField DataField="Date" HeaderText="Date" />
    <asp:Label ID="lblCount" runat="server" />



using System.Data;


Imports System.Data



protected void btnSave_Click(object sender, EventArgs e)
    DataTable dt = new DataTable();
    DateTime startDate = DateTime.Parse(Request.Form[TextBox1.UniqueID]); ;
    DateTime endDate = DateTime.Parse(Request.Form[TextBox2.UniqueID]);
    for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
        if (date.DayOfWeek == DayOfWeek.Monday)
            dt.Rows.Add(date.DayOfWeek, date);

    IEnumerable<DataRow> result = (from products in dt.AsEnumerable()
                                    select products).Where((c, i) => i % 2 == 0);
    DataTable dt1 = dt.Clone();
    foreach (DataRow row in result)
    lblCount.Text = "Total number of monday in month : " + result.Count().ToString();
    gvDayes.DataSource = dt1;


Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim dt As DataTable = New DataTable()
    Dim startDate As DateTime = DateTime.Parse(Request.Form(TextBox1.UniqueID))
    Dim endDate As DateTime = DateTime.Parse(Request.Form(TextBox2.UniqueID))
    Dim date1 As DateTime = startDate
    While date1 <= endDate
        If date1.DayOfWeek = DayOfWeek.Monday Then
            dt.Rows.Add(date1.DayOfWeek, date1)
        End If

        date1 = date1.AddDays(1)
    End While
    Dim result As IEnumerable(Of DataRow) = (From products In dt.AsEnumerable() Select products).Where(Function(c, i) i Mod 2 = 0)
    Dim dt1 As DataTable = dt.Clone()
    For Each row As DataRow In result

    lblCount.Text = "Total number of monday in month : " & result.Count().ToString()
    gvDayes.DataSource = dt1
End Sub