Last active
June 30, 2023 14:36
-
-
Save dinizgb/8d1e9b45ff57ce2fb09ba96fe17a4d17 to your computer and use it in GitHub Desktop.
Javascript function to add or decrease days to a date.
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 add or decrease days to a date | |
* @param {string} date - With the date (With at least yyyy-mm-dd date format) | |
* @param {number} days - With the days | |
* @param {boolean} action - True to increase days or false to decrease days | |
* @returns {string} With the the new date | |
*/ | |
export const addOrDecreaseDaysToDate = (date: string, days: number, action: boolean): string => { | |
const result = new Date(date); | |
action ? result.setDate(result.getDate() + days) : result.setDate(result.getDate() - days); | |
return result.toISOString(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment