Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

set-date-picker-range-with-in-a-financial-year-based-on-the-document

function getCurrentFinancialYear(strDocDate) {
    var startYear = "";
    var endYear = "";
    var docDate = new Date(strDocDate);
    if ((docDate.getMonth() + 1) <= 3) {
        startYear = docDate.getFullYear() - 1;
        endYear = docDate.getFullYear();
    } else {
        startYear = docDate.getFullYear();
        endYear = docDate.getFullYear() + 1;
    }
    console.log({startDate : startYear+"-03-01", endDate: endYear+"-03-31" });
    return {startDate : startYear+"-03-01", endDate:  endYear+"-03-31" };
}

$(document).ready(function () {
  $('.datepicker').datepicker({
      format: 'yyyy-mm-dd',
      maxViewMode: 0,
      todayBtn: "linked",
      clearBtn: true,
      autoclose: true,
      todayHighlight: true,
      startDate: getCurrentFinancialYear($('input.datepicker').val()).startDate,
      endDate: getCurrentFinancialYear($('input.datepicker').val()).endDate
  });
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
5+5 =