Skip to content

Instantly share code, notes, and snippets.

@segdeha
Created April 15, 2021 16:55
Show Gist options
  • Save segdeha/3d1b9100ee9c41fc13f6aeffe78eb9e5 to your computer and use it in GitHub Desktop.
Save segdeha/3d1b9100ee9c41fc13f6aeffe78eb9e5 to your computer and use it in GitHub Desktop.
Return the number of the week (e.g., 16 out of 52 weeks)
function getWeekNumber() {
const now = new Date()
const oneJan = new Date(now.getFullYear(), 0, 1)
const numDays = Math.floor((now - oneJan) / (24 * 60 * 60 * 1000))
return Math.ceil(( now.getDay() + 1 + numDays) / 7)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment