Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function getFirstDayOfWeek(date) {
if (!date) {
date = new Date();
}
var firstDay = new Date(date - (date.getDay() - 1) * 86400000);
return firstDay;
}
function getLastDayOfWeek(date) {
if (!date) {
date = new Date();
}
var firstDay = new Date(date - (date.getDay() - 1) * 86400000);
var lastDay = new Date((firstDay / 1000 + 6 * 86400) * 1000);
return lastDay;
}
function getFirstDayOfMonth(date) {
if (!date) {
date = new Date();
}
var firstDay = new Date(date.getYear(), date.getMonth(), 1);
return firstDay;
}
function getLastDayOfMonth(date) {
if (!date) {
date = new Date();
}
var nextFirstDayOfMonth = new Date(date.getYear(), date.getMonth() + 1, 1);
var lastDay = new Date(nextFirstDayOfMonth - 86400000);
return lastDay;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.