How to change view mode in bootstrap datepicker like yyyy-mm

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this post i will show you How to change view mode in bootstrap datepicker like yyyy-mm? When we are working on our laravel application and we must need use the datepicker picker but sometimes i need only select only year and month because sometimes we have to filter data with selected month and year. When I was working first time and i did search a lot and also check the options of datepicker js but i can’t do this that because i was make wrong maybe.

But at last i was found the minViewMode option of datepicker library and i can did that if you also need to make format as like as mm-yyyy or yyyy-mm then you need to set minviewmode as like as on this way :

Example:
<html lang="en">
<head>
    <title>Bootstrap - datepicker change view mode like yyyy-mm</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 - datepicker change view mode like yyyy-mm</h2>
     <input class="date-newform-control" style="width: 300px;" type="text">


	<script type="text/javascript">
	    $('.date-new').datepicker({
	       minViewMode: 1,
	       format: 'yyyy-mm'
	     });
	</script>
</div>


</body>
</html>

Read Also :Laravel Join with Subquery in Query Builder Example

Thanks for read. I hope it help you. For more you can follow us on facebook.

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →