Calculate the Date Three Months Prior using JavaScript

Last Updated : 1 Sep, 2026

Calculating the date three months prior in JavaScript can be done using the getMonth() and setMonth() methods of the Date object. These methods allow you to retrieve the current month and move the date backward by three months.

  • Create a Date object for the current or specified date.
  • Use getMonth() to retrieve the current month.
  • Subtract three from the month and update the date using setMonth().

Approach: Using getMonth() and setMonth()

The getMonth() method returns the month as a zero-based value, while setMonth() updates the month of a Date object. By subtracting 3 from the value returned by getMonth(), we can calculate the date three months prior.

Example 1: In this example, we calculate the date three months prior to the current date.

JavaScript
let d = new Date();

console.log("Today's Date: " + d.toLocaleDateString());

d.setMonth(d.getMonth() - 3);

console.log("3 Months Prior Date: "
    + d.toLocaleDateString());

Example 2: In this example, we calculate the date three months prior to a specified date.

JavaScript
let d = new Date("2018/12/02");

console.log("Date: " + d.toLocaleDateString());

d.setMonth(d.getMonth() - 3);

console.log("3 Months Prior Date: "
    + d.toLocaleDateString());

Output
Date: 12/2/2018
3 Months Prior Date: 9/2/2018
Comment