locked
Validation RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I have below code and i want Day should be 1 always in txt_Date1 . In txt2_Date2 date should be automatically the last date of that month

    <asp:TextBox ID="txt_Date1" runat="server" CssClass="form-control datepicker" ></asp:TextBox>

    <asp:TextBox ID="txt_Date2" runat="server" CssClass="form-control datepicker" ></asp:TextBox>

    Thanks

    Tuesday, November 13, 2018 10:00 AM

Answers

  • User839733648 posted

    Hi JagjitSingh,

    It seems that you've used something related to bootstrap datepicker, right?

    In my opinion, you could use .daterangepicker() function to set the start date and end date.

    When you choose any month's 1st day, then the txt_Date will show the end day of that month.

    For more, you could refer to the code below.

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
        <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" />
        <script type="text/javascript" src="https://cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
        <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />
        <script type="text/javascript">
            $(function () {
                $('#txt_Date1').daterangepicker({
                    singleDatePicker: true,
                    locale: { format: "DD-MM-YYYY" }
                }, function (start, end, label) {
                    if (start) {
                        var end = start.clone().endOf('month');
                        $('#txt_Date2').data('daterangepicker').setStartDate(end.startOf('day'));
                        $('#txt_Date2').data('daterangepicker').setEndDate(end.endOf('day'));
                    }
                });
                $('#txt_Date2').daterangepicker({
                    singleDatePicker: true,
                    locale: { format: "DD-MM-YYYY" }
                });
            })
    
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="txt_Date1" runat="server" CssClass="form-control datepicker"></asp:TextBox>
                <asp:TextBox ID="txt_Date2" runat="server" CssClass="form-control datepicker"></asp:TextBox>
            </div>
        </form>
    </body>
    </html>

    result:

    Best Regards,

    Jenifer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 14, 2018 2:57 AM