Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i try to get current year in calendar.. now year is 2016 so i don't want past years and future years only want current year ... and also month is June or any other month so i don't future months only want current and past months . when year 2017 then in calendar must be year 2017 ..when month is June or any other month then not able to select future months .. we only select only current month and past months according to year
e,g, current month is June so
Jan 2016.... June 2016

this is what i try

What I have tried:

XML
<input type="date" ID="fromdate"/>  
    <input type="date" ID="todate"/>  

 <script type="text/javascript">
          $(function () {
              var currentYear = (new Date).getFullYear();
              var currentMonth = (new Date).getMonth() + 1;
              var currentDay = (new Date).getDate();

              $("#fromdate").datepicker({ minDate: new Date((currentYear - 1), 12, 1), dateFormat: 'dd/mm/yy', maxDate: new Date(currentYear, 11, 31) });
          });
  </script>
 <script type="text/javascript">
     $(function () {
         var currentYear = (new Date).getFullYear();
         var currentMonth = (new Date).getMonth() + 1;
         var currentDay = (new Date).getDate();

         $("#todate").datepicker({ minDate: new Date((currentYear - 1), 12, 1), dateFormat: 'dd/mm/yy', maxDate: new Date(currentYear, 11, 31) });
     });
  </script>



but when i select calendar this show past year and months also and also future years

any solution?
Posted
Updated 20-Jun-16 2:07am
v2

1 solution

Simple changes and you should be okay.

Refer - [Demo] Disable Future Dates and Past Years - JSFiddle[^].
 
Share this answer
 
Comments
super_user 21-Jun-16 0:53am    
which changes?
super_user 21-Jun-16 0:54am    
thanks you much
super_user 21-Jun-16 1:14am    
hi.. it works but calendar formatting is out.. when i try calendar look like this please check link.. http://oi66.tinypic.com/opxr0k.jpg

and i want this http://oi64.tinypic.com/169oy8j.jpg

2nd link calendar appear but functionality is not perform whereas 1st link calendar appear below the 2nd link calendar and functionality perform .. and i need 2nd link calendar with functionality ....
You are actually mixing things. If you see my demo, I have declared like this...

<input type="text" ID="fromdate" />
<input type="text" ID="todate" />

Mark the type. It is "text" not "date". You are using jQuery DatePicker, so you need to have type="text".

You also have to refer the below resources of jQuery UI.
1. https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css
2. https://code.jquery.com/ui/1.11.4/jquery-ui.js

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900