Skip to content

Instantly share code, notes, and snippets.

@phirework
Created November 6, 2019 14:49
Show Gist options
  • Save phirework/98e171b0d67a4442f2f383accff8e50d to your computer and use it in GitHub Desktop.
Save phirework/98e171b0d67a4442f2f383accff8e50d to your computer and use it in GitHub Desktop.
const getWeekNum = (date) => {
// create new Date obj to avoid mutating input
const now = new Date(date.getUTCFullYear(), date.getMonth(), date.getDate());
now.setMilliseconds(0);
const yearStart = new Date(now.getUTCFullYear(), 0, 1);
const milisecsInWeek = 7 * 24 * 60 * 60 * 1000;
return Math.floor((now.valueOf() - yearStart.valueOf()) / milisecsInWeek) + 1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment