Created
January 28, 2011 03:22
-
-
Save sp3c73r2038/799775 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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