To use the addWeeks function from date-fns library in JavaScript, you need to first install the library using npm by running the following command in your terminal:
index.tsx28 chars2 lines
After installation, you can start using the addWeeks function in your code by importing it from the library:
index.tsx37 chars2 lines
The addWeeks function takes two arguments:
Here's an example of how to use the addWeeks function to add two weeks to the current date:
index.tsx129 chars5 lines
In this example, the now
variable is a date object representing the current date and time. The addWeeks
function is used to add two weeks to the current date, and the result is stored in the twoWeeksLater
variable. The console.log
statement outputs the result, which is the date and time two weeks from now.
That's it! You can now use the addWeeks
function from date-fns library to add or subtract weeks from a date object in JavaScript code.
gistlibby LogSnag