show financial year from date and to date

RAVI 896 Reputation points


I have two requriements

1) Current financial year Is Apr-2023 TO Mar-2024

In dropdownlist it has to show previous 3 years financial format as below for example on pageload

Apr-2023 TO Mar-2024

Apr-2022 TO Mar-2023

Apr-2021 TO Mar-2022

2) On Selecting From Dropdownlist it has to show mar first date and end date of respective years

For example i have textbox1 and textbox2 if i select APR-2022 TO Mar-2023 In textbox1 i want to show without postback using javascript or jquery like this format

01-APR-2022 and in textbox2 i want 31-MAR-2023

thanking you

A set of technologies in the .NET Framework for building web applications and XML web services.
3,240 questions
0 comments No comments
{count} votes

Accepted answer
  1. AgaveJoe 26,181 Reputation points

    If I understand correctly you want a jQuery example without a postback.

    Populate the select.

        public partial class FiscalYear : System.Web.UI.Page
            protected void Page_Load(object sender, EventArgs e)
            private void PopulateFiscalYears()
                int FiscalYear = DateTime.Now.Month < 4 ?  DateTime.Now.Year : DateTime.Now.Year + 1;
                FiscalYears.Items.Add(new ListItem ("--Select--", ""));
                for (int i = 0; i < 3; i++)
                    FiscalYears.Items.Add(new ListItem
                        "Apr-" + (FiscalYear - i - 1).ToString() + " TO Mar-" + (FiscalYear-i).ToString(),
                        "01-Apr-" + (FiscalYear -i - 1).ToString() + ",31-Mar-" + (FiscalYear - i).ToString()

    JQuery to populate two textboxes when the select changes.

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
            <asp:DropDownList ID="FiscalYears" runat="server"></asp:DropDownList>
            <asp:TextBox ID="FromDate" runat="server"></asp:TextBox>
            <asp:TextBox ID="ToDate" runat="server"></asp:TextBox>
         $('#<%=FiscalYears.ClientID%>').change(function () {
             var dates = $(this).val().split(",");


    Perhaps in future post you can you at least try to write the code?

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Lan Huang-MSFT 25,386 Reputation points Microsoft Vendor

    Hi @RAVI,

    I designed the code based on your needs, using getFullYear(), getMonth(), and getDate() methods to dynamically change the fiscal year based on the change in date.

    <html xmlns="">
    <head runat="server">
        <script src="Scripts/jquery-3.4.1.min.js"></script>
            $(document).ready(function () {
                const monthNames = ["Jan", "Feb", "Mar", "Apr",
                    "May", "Jun", "Jul", "Aug",
                    "Sep", "Oct", "Nov", "Dec"];
                var currentYear = new Date().getFullYear();
                var currentMonth = new Date().getMonth();
                const monthName = monthNames[currentMonth];
                for (var i = 0; i < 5; i++) {
                    var nextY = currentYear - 1;
                    var nextM = monthNames[currentMonth + 1];
                    var firstDay = ("0" + new Date(currentYear, currentMonth, 1).getDate()).slice(-2);
                    var lastDay = new Date(currentYear-1, currentMonth+1, 0).getDate();
                    var value = firstDay + "-" + nextM+ "-" + nextY + " TO " + lastDay + "-" + monthName + "-" + currentYear;
                    var text = nextM + "-" + nextY + " TO " + monthName + "-" + currentYear;
                    $('#financialYear').append(new Option(text, value));
                $('#financialYear').change(function () {
                    var dates = $(this).val().split("TO");
        <form id="form1" runat="server">
         <select id="financialYear" onchange=""></select>
            <asp:TextBox ID="FromDate" runat="server"></asp:TextBox>
            <asp:TextBox ID="ToDate" runat="server"></asp:TextBox>

    User's image

    Best regards,
    Lan Huang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.