14

I want the user to specify their birthday or anniversary date (without year) in a form. For this, I want to use jquery datepicker but it should not show any year option at all. How to do it?

I tried modifying the code in this so question by making changeDay: true and changeYear: false but could not get it to work.

Community
  • 1
  • 1
tanon
  • 143
  • 1
  • 1
  • 5

7 Answers7

13

You could do:

$('#date').datepicker( {
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        dateFormat: 'dd MM'
    });

fiddle http://jsfiddle.net/u8GnD/1/

Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
12

set the css to hide the year and the dateFormat as K6t said

.ui-datepicker-year{
    display:none;
}
Emil Condrea
  • 9,705
  • 7
  • 33
  • 52
7

You can hide year from a datepicker like this :

$(".daypicker").datepicker( { 
    changeYear: false, 
    dateFormat: 'MM-dd',
}).focus(function () {
    $(".ui-datepicker-year").hide();
});

It wont affect to other datepickers in same page.

Rafi
  • 833
  • 13
  • 17
2
$("#datepicker").datepicker( {
format: "dd-MM",
viewMode: "months", 
maxViewMode: "months"
});

this will surely hide year from datepicker view, will show only month and days panel

Vivek Chaudhari
  • 1,930
  • 1
  • 14
  • 20
0
$( function() {
     var date = $('#datepicker').datepicker({
        dateFormat: 'yy-mm-dd',
        changeMonth: true, 
        changeYear: false}).val();
});
Sohail
  • 587
  • 7
  • 25
  • 3
    Always add explanation to your answer. Mere code does not help. – Saqib Omer Nov 23 '17 at 11:41
  • 1
    This answer might or might not solve the issue the OP experience, so please always add an explanation to you answer to clarify how it might fix the issue – Gerhard Nov 23 '17 at 11:52
0

I may be late on the show but I found all of the above answers/suggestions and comments to be almost correct but someone might miss the correct jquery plugin to make the code work.

Someone struggling to make it done pls consider changing your javascript plugins first, and use the following instead


<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
Shedrack
  • 656
  • 7
  • 22
-2

change dateFormat as

dateFormat: 'dd MM',

in datePicker.js file

K6t
  • 1,821
  • 1
  • 13
  • 21