-1

I want to find startdate (Monday) of the specified date and lastdate of the specified date in Javascript. So for example my date is 2015-11-20 , then the startdate should be 2015-11-16 and lastdate should be 2015-11-21

Techy
  • 41
  • 4

2 Answers2

1

You can use moment.js to do this super easily.

var start = moment('2015-11-20').startOf('week').format('YYYY-MM-DD');

Or

var end = moment('2015-11-20').endOf('week').format('YYYY-MM-DD');
Tim Sheehan
  • 3,994
  • 1
  • 15
  • 18
1

maybe this can help you

var date = new Date();
var day = date.getDay();

$('#start_date').text("Start date: " + subDays(date, day-1));

$('#end_date').text("End date: " + addDays(date, 6-day));


function subDays(date, days){
    return new Date(date.getTime() - (days * 24 * 60 * 60 * 1000)).toISOString().substr(0,10);
}

function addDays(date, days){
 return new Date(date.getTime() + (days * 24 * 60 * 60 * 1000)).toISOString().substr(0,10);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div id='start_date'></div>
<br>
<div id='end_date'></div>