Sangeetha.V
Sangeetha.V

Reputation: 115

How can I get given month start date and end date in javascript

I need to get given month start date and end date.

   var currentDate = new Date();
   var currentMonth = currentDate.getMonth();

Upvotes: 0

Views: 5312

Answers (1)

yiabiten
yiabiten

Reputation: 810

Try this:

function MyCtrl($scope){
   var date = new Date(), year = date.getFullYear(), month = date.getMonth();
   var firstDay = new Date(year, month, 1);
   var lastDay = new Date(year, month + 1, 0);
   $scope.firstDay = firstDay ;
   $scope.lastDay = lastDay ;
   $scope.date = date ;    
}

And:

<div ng-app ng-controller="MyCtrl">
<ul>
    <li>{{date | date:'yyyy-MM-dd'}}</li> 
    <li>{{firstDay | date:'yyyy-MM-dd'}}</li> 
    <li>{{lastDay | date:'yyyy-MM-dd'}}</li> 
</ul>

Upvotes: 6

Related Questions