how to use the subminutes function from date-fns in javascript

To use the subminutes function from the date-fns library in javascript, follow the steps below:

  1. Install the date-fns library using npm by running the following command in your terminal:

    index.tsx
    npm install date-fns
    
    21 chars
    2 lines
  2. Import the subMinutes function from the date-fns library:

    index.tsx
    import { subMinutes } from 'date-fns';
    
    39 chars
    2 lines
  3. Use the subMinutes function by passing in a date object and the number of minutes you want to subtract:

    index.tsx
    const date = new Date();
    const subbedDate = subMinutes(date, 30);
    console.log(subbedDate); // returns a new date object 30 minutes earlier than the original date
    
    162 chars
    4 lines

The subMinutes function is used to subtract a specified number of minutes from a given date object and return a new date object.

gistlibby LogSnag