Reputation: 43933
In javascript, well node.js, if I have a date
object, how can I get the date object of the end of the week, like if the day of the initial object was Wednesday (regardless of time), then how can I get the date object but with it moved 4 days up and to 12:00 am, so Sunday midnight.
Thanks
Upvotes: 0
Views: 131
Reputation: 36609
Try this:
var dateObj = new Date();
var day = dateObj.getDay();
var diff = 7 - day;
var neDate = new Date();
neDate.setDate(dateObj.getDate() + diff);
document.getElementById('data').innerText = neDate;
<div id='data'></div>
Upvotes: 0
Reputation: 13581
use moment.js and its endOf() function
var m = moment(new Date(2011, 2, 12, 5, 0, 0));
m.endOf("week");
Upvotes: 1