Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How display only years in input Bootstrap Datepicker?

I am using the following code to display only the years:

$("#datepicker").datepicker( {viewMode: "years", minViewMode: "years"}); 

but input appears in the format "dd/mm/yyyy"

How can I solve this since I do not have the format "yyyy"?

like image 297
John Avatar asked Oct 29 '12 19:10

John


People also ask

How do you only show month and year in date picker?

Set changeMonth and changeYear to true so that Month and Year appear as Dropdown. Set date format to "MM yy". jQuery DatePicker has "onClose" event, which is called when Datepicker gets closed. So using this event, fetch the selected Month and Year and setDate of Datepicker.

How do I display only the year in HTML?

Input Type Month The <input type="month"> allows the user to select a month and year. Depending on browser support, a date picker can show up in the input field.


1 Answers

Try this

$("#datepicker").datepicker({      format: "yyyy",      viewMode: "years",       minViewMode: "years"  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>  <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css" rel="stylesheet"/>  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>      <input type="text" id="datepicker" />
$("#datepicker").datepicker( {     format: " yyyy", // Notice the Extra space at the beginning     viewMode: "years",      minViewMode: "years" }); 
like image 85
Zoltan Toth Avatar answered Sep 28 '22 14:09

Zoltan Toth