The JavaScript setUTCDate function is useful for setting the UTC day of the month on a given date according to Universal Coordinated Time zone.
The syntax of the setUTCDate Date function is:
Date.setUTCDate(Day_Number)
Parameter: The setUTCDate function accepts an integer representing the day of the month number between 0 and 31. If we pass any number outside this range, the date will roll back or forward.
Return Value: It updates the UTC day of the month number as per the given value.
JavaScript setUTCDate example
In the following example, we use the setUTCDate function to set the current UTC day to the 30th according to the Coordinated Universal Time zone.
const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCDate(30);
console.log(dt.toUTCString());
Tue, 16 Jun 2026 05:48:44 GMT
Tue, 30 Jun 2026 05:48:44 GMT
Example 2: In this JScript example, we use the Date() constructor to parse a custom string date and apply the setUTCDate to set the day of a custom date to 31 according to universal time UTC.
const dt = new Date("January 1, 2023 10:11:19");
console.log(dt.toUTCString());
dt.setUTCDate(30);
console.log(dt.toUTCString());
Sun, 01 Jan 2023 04:41:19 GMT
Mon, 30 Jan 2023 04:41:19 GMT
Example 3: If we set the Month number to more than 31, then JavaScript setUTCDate will go to the next month. In the example below, we used setUTCDate with 45 as the day of the month number. As the current month is June, which contains 30 days, it updates the month to July and sets the day of the month to 15 (remaining days after 45 – 30).
const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCDate(45);
console.log(dt.toUTCString());
Tue, 16 Jun 2026 05:50:35 GMT
Wed, 15 Jul 2026 05:50:35 GMT
Example 4: If we use 0 as the setUTCDate() parameter, it returns the last month’s end date, and -1 means last month’s last but one date.
const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCDate(-1);
console.log(dt.toUTCString());
Tue, 16 Jun 2026 05:52:41 GMT
Sat, 30 May 2026 05:52:41 GMT