Skip to content

Instantly share code, notes, and snippets.

@rbk
Created July 24, 2019 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbk/44981da37661bb9daa461672c95e5b48 to your computer and use it in GitHub Desktop.
Save rbk/44981da37661bb9daa461672c95e5b48 to your computer and use it in GitHub Desktop.
Last N Dates
/*
*
* 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