How do you get the first date of the month from a date in javascript?

Get the First Day of a Month #

To get the first day of a month, use the Date() constructor to create a date object, passing it the year, month and 1 for the day as parameters. The Date object will contain the first day of the month.

Copied!

function getFirstDayOfMonth(year, month) { return new Date(year, month, 1); } // 👇️ First day of CURRENT MONTH const date = new Date(); const firstDayCurrentMonth = getFirstDayOfMonth( date.getFullYear(), date.getMonth(), ); console.log(firstDayCurrentMonth); // 👉️ Sat Oct 01 2022 // 👇️ First day of month January 2025 const firstDayJanuary = getFirstDayOfMonth(2025, 0); console.log(firstDayJanuary); // Wed Jan 01 2025

We passed the following 3 arguments to the Date() constructor:

  1. The year
  2. The month
  3. The day

We used the Date.getFullYear method to get the current year.

We used the Date.getMonth method to get the current month.

The method returns an integer from 0 (January) to 11 (December).

Months are zero-based in JavaScript, meaning 0 is January and 11 is December.

We hardcoded 1 for the day because we want the first day of the month.

The getFirstDayOfMonth function can be used to get the first day of any month, here are some examples.

Copied!

function getFirstDayOfMonth(year, month) { return new Date(year, month, 1); } console.log(getFirstDayOfMonth(2026, 0)); // 👉️ Thu Jan 01 2026 console.log(getFirstDayOfMonth(2031, 0)); // 👉️ Wed Jan 01 2031 console.log(getFirstDayOfMonth(2036, 0)); // 👉️ Tue Jan 01 2036

The tricky thing to remember is that months are zero-based and go from 0 (January) to 11 (December).

This gets handled when you use the getMonth method as it returns an integer from 0 to 11.

If you want to make your code more readable, extract the value for the month into a variable.

Copied!

function getFirstDayOfMonth(year, month) { return new Date(year, month, 1); } const january = 0; console.log(getFirstDayOfMonth(2026, january)); // 👉️ Thu Jan 01 2026

Further Reading #

  • Get the Last Day of a Month in JavaScript
  • Get the Last Day of the Year in JavaScript

Very simple, no library required:

var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);

or you might prefer:

var date = new Date(), y = date.getFullYear(), m = date.getMonth();
var firstDay = new Date(y, m, 1);
var lastDay = new Date(y, m + 1, 0);

EDIT

Some browsers will treat two digit years as being in the 20th century, so that:

new Date(14, 0, 1);

gives 1 January, 1914. To avoid that, create a Date then set its values using setFullYear:

var date = new Date();
date.setFullYear(14, 0, 1); // 1 January, 14

How do you find the first date of the current month?

1. First day of current month: select DATEADD(mm, DATEDIFF(m,0,GETDATE()),0): in this we have taken out the difference between the months from 0 to current date and then add the difference in 0 this will return the first day of current month.

How do you get the first working day of the month in JavaScript?

To get the first day of a month, use the Date() constructor to create a date object, passing it the year, month and 1 for the day as parameters. The Date object will contain the first day of the month.

How do you get the first Monday of the month in JavaScript?

how to calculate first monday of the month in js.
function lastDayOfMonth(y,m,dy) {.
var days = {sun:0,mon:1,tue:2,wed:3,thu:4,fri:5,sat:6}.
,dat = new Date(y+'/'+m+'/1').
,currentmonth = m..
,firstday = false;.
while (currentmonth === m){.
firstday = dat. getDay() === days[dy] || firstday;.
dat. setDate(dat..

What is getDate () in JavaScript?

getDate() The getDate() method returns the day of the month for the specified date according to local time.