In a data report query, it is often necessary to set the date range of the query, such as querying the month of 2018-02-01 to 2018-02-28 data, when you need to provide a quick month query button:
Such as:
The general date and month day between the "-" or "/" and so on to split open, simple judgment of the current month processing can be. In addition, how to get the maximum number of days for the selected month is key, which can be handled with the help of the JS self-contained date function, the key is to navigate to the last day of the selected month
The key code is as follows:
function Changemonth(type){ //Gets the date in the current input box varS_date= $("Input[name= ' s_date ')").Val(); varE_date= $("Input[name= ' e_date ')").Val(); varArr= s_date.Split("-"); varYear= parseint(arr[0]),Month= parseint(arr[1]),Day= parseint(arr[2]); varYear2=Year,Month2,Day2; //Take one months if(Type== ' pre '){Month2=Month- 1; if(Month2== 0){ //If current is JanuaryMonth2= A;Year2=Year- 1; } } Else {Month2=Month+ 1; if(Month2== -){Month2= 1;Year2=Year+ 1; } } //Output The first day of the selected month varStart=Year2+ "-" +Month2+ "-" + "1"; //Get current varDate= New Date(start); varYear= Date.getFullYear(); varMonth= Date.GetMonth()+1; varD= New Date(Year,Month,0); //The day before the next one months varEnd=Year2+ "-" +Month2+ "-" + D.getDate(); Console.Log(Start,End; //Set the value of the current time input $("Input[name= ' s_date ')").Val(start); $("Input[name= ' e_date ')").Val(end); }
JS how to get the current one month, the next one months and the month contains the days