I am using bootstrap datepicker,but it show date,month and year i want show year only in datepicker in textbox
Asked
Active
Viewed 1,451 times
1
-
3Possible duplicate of [jQuery UI DatePicker to show year only](http://stackoverflow.com/questions/13528623/jquery-ui-datepicker-to-show-year-only) – Mohit Tanwani Sep 24 '16 at 10:58
1 Answers
2
try this:
$("#datepicker").datepicker( {
format: " yyyy", //see there is extra space in format, dont remove it
viewMode: "years",
minViewMode: "years"
});
use this :
<html lang="en">
<head>
<title>Bootstrap - year picker only example</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>
</head>
<body>
<div class="container text-center">
<h2>Bootstrap - year picker only example</h2>
<input class="date-own form-control" style="width: 300px;" type="text">
<script type="text/javascript">
$('.date-own').datepicker({
minViewMode: 2,
format: 'yyyy'
});
</script>
</div>
</body>
</html>

Rohit Yadav
- 47
- 1
- 6
-
already i tried here my code $("#yearofpub").datepicker ({ format: " yyyy", viewMode: "years", minViewMode: "years" }); but not working i want only year – Shiva Prakashan Sep 24 '16 at 10:53
-
i used datepicker multiple place in my application this same bootstrap datepicker plugin ,if any solution are there in jquery show only year in particular textbox – Shiva Prakashan Sep 24 '16 at 11:02
-
change the ID or class for each box where you used datepicker and then define their format using their ID or Class . – Rohit Yadav Sep 24 '16 at 11:05