.setDate()

Anonymous contributor's avatar
Anonymous contributor
Published Jun 15, 2023
Contribute to Docs

The .setDate() method changes the day of the month according to local time.

Syntax

myDate.setDate()

The .setDate() method changes the day of the month of a provided date according to local time.

Example

In the example below, the myDate variable takes the provided date and then the .setDate() method is applied to return a modified date.

const myDate = new Date('2023-01-01');
myDate.setDate(24);
console.log(myDate.getDate());

This results in the following output:

24

All contributors

Contribute to Docs

Learn JavaScript on Codecademy