Skip to content Skip to sidebar Skip to footer

How To Get The Selected Year In Datepicker?

I am using datepicker for my input name birth_day. And I want to calculate the age from the current year and selected year. current_yr - selected_yr but I have no idea on how can I

Solution 1:

Do you mean:

$(function() {
     $("#id_birth_date").datepicker({
           onSelect: function(dateText, inst) {
              var startDate = newDate(dateText);
              var selectedYear = startDate.getFullYear(); // selected year
           }
     });
});

Solution 2:

It will be possible.. after selecting date from datepicker

You will get property of datepicker1.year which will help you get year

Or

After retrieving date into string use Convert.Toint32(strDate1)-Convert.Toint32(strDate2) ;

..Try it...Otherwise post you code,...

Solution 3:

You should be able to utilize the val() function.

Solution 4:

The selected answer has a problem: the dateText may not be parsed because it depends on text which can be customised. Below is the enhanced accurate answer. Otherwise you will end up using an undefined date object:

$(function() {
     $("#id_birth_date").datepicker({
           onSelect: function(dateText, inst) {
              var startDate = newDate(inst.selectedYear, inst.selectedMonth, inst.selectedDay);
              var selectedYear = startDate.getFullYear(); // selected year
           }
     });
});

Post a Comment for "How To Get The Selected Year In Datepicker?"