VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-date-addmonths-api/

⇱ Node.js Date.addMonths() API - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js Date.addMonths() API

Last Updated : 12 Mar, 2021

The date-and-time.Date.addMonths() is a minimalist collection of functions for manipulating JS date and time module which is used to add the extra Month to the existing date and time.

Required Module: Install the module by npm or used it locally.

  • By using npm.
npm install date-and-time --save
  • By using CDN link.
<script src="/path/to/date-and-time.min.js"></script>

Syntax:

addMonths(dateObj, months)

Parameters: This method takes the following arguments as a parameter:

  • dateobject: It is the string object of the date.
  • months: It is the number of months.

Return Value: This method returns updated date and time.

Example 1:

Run the index.js file using the following command:

node index.js

Output:

updated date and time : 
Thu Mar 09 2023 00:15:16 GMT+0530 (India Standard Time)

Example 2:

Run the index.js file using the following command:

node index.js

Output:

updated date and time : 
Wed Sep 20 2023 00:16:10 GMT+0530 (India Standard Time)

Reference: https://github.com/knowledgecode/date-and-time#addmonthsdateobj-months

Comment

Explore