Last active
June 30, 2023 16:15
-
-
Save dinizgb/e32b9da94432128eeed12c8e281ab31d to your computer and use it in GitHub Desktop.
Javascript function to get last dates within a determined period.
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
/** | |
* Function to get last dates within a determined period | |
* @param {Number} period - With the period | |
* @returns {Array} With an Array with dates in ISO format (YYYY-MM-DDTHH:MM:SS.sssZ) as string | |
*/ | |
export const getLastDatesWithinPeriod = (period: number): Array<string> => { | |
const today = new Date(); | |
const days = []; | |
for (let i = 0; i < period; i++) { | |
const day = new Date(today); | |
day.setDate(day.getDate() - i); | |
days.push(day.toISOString()); | |
} | |
return days; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment