Created
June 29, 2020 17:22
-
-
Save kirkegaard/e19b35f9f52a74782abe675ea6886ba8 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
const getWeekNumber = (date) => { | |
const pd = new Date(date); | |
const sj = new Date(pd.getFullYear(), 0, 1); | |
const wk = Math.ceil((((pd - sj) / 86400000) + sj.getDay() + 1) / 7); | |
return wk; | |
} | |
console.log( | |
getWeekNumber('2020-01-01'), | |
getWeekNumber('2020-01-14'), | |
getWeekNumber('2020-06-29'), | |
); | |
// 1 3 27 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment