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
Asked
Active
Viewed 48 times
-1
-
2Look here http://stackoverflow.com/questions/4156434/javascript-get-the-first-day-of-the-week-from-current-date – RiccardoC Nov 20 '15 at 11:31
-
This works for finding first day but how do I fond the last day? – Techy Nov 20 '15 at 12:55
2 Answers
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>