Created
December 4, 2021 13:43
-
-
Save hebertcisco/3964ff6dd02735b2d85ef7f3aac41ea3 to your computer and use it in GitHub Desktop.
Funtion to get the last months as string eg: 'jan'
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
export const getLastMonths = (many: number): string[] => { | |
const months = []; | |
const currentMonth = new Date().getMonth(); | |
for (let i = 0; i < many; i++) { | |
months.push( | |
new Date(new Date().setMonth(currentMonth - i)).toLocaleString( | |
'default', | |
{ month: 'short' }, | |
), | |
); | |
} | |
return months.reverse(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment