Created
July 24, 2019 20:32
-
-
Save rbk/44981da37661bb9daa461672c95e5b48 to your computer and use it in GitHub Desktop.
Last N Dates
This file contains hidden or 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
/* | |
* | |
* Starting today, get each date for the last N days. | |
* | |
*/ | |
const lastNDates = (n) => { | |
let result = [] | |
let d = new Date() | |
let rd = `${d.getFullYear()}-${d.getMonth()+1}-${d.getDate()}` | |
result.push(rd) | |
for(let i=0; i < n; i++) { | |
d = new Date(d.getTime()-(1000*60*60*24)) | |
rd = `${d.getFullYear()}-${d.getMonth()+1}-${d.getDate()}` | |
result.push(rd) | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment